ap computer science help?

th3dumbguy

Senior member
Feb 4, 2005
242
0
0
im not taking the test myself but my friend is and he wants me to ask something so he can be sure so here it goes...

public interface A
public class B implements A
public class C extends B

which declarations are right

B thisC = new C();
A thisB = new B();
A thisA = new A();

which ones of those would work?

i know the first one works but does the 2nd and 3rd work?
 

BigJ

Lifer
Nov 18, 2001
21,330
1
81
Tell your friend to think about what an interface actually is.

Then tell your friend to think about what implements and extends means, and what concepts those words actually refer to. It's all in the book and will serve him much better to know WHY than it will for us to tell him.
 

Rayden

Senior member
Jun 25, 2001
790
1
0
Uh. In Java you can do all but the third. You cant do the third because you can't instantiate an interface.

interFace Pet{}
Animal implements Pet{}
Dog extends Animal{}


Animal dog = new Dog();
Pet myPet= new Animal();

those are legal.

I checked using:

Comparable test = new BigInteger("10");
Component test3 = new JFrame();

Comparable is an interface. and JFrame extends Component.
 

eLiu

Diamond Member
Jun 4, 2001
6,407
1
0
think of it this way...

public interface cars
public class Ford implements cars
public class F150 extends Ford

Ford F150=new F150();
Cars Ford=new Ford();
Cars Cars = new Cars();

The first two make intuitive sense. They're the ones that are right.

Some more concrete explanation:
The last one is wrong b/c you can't instantiate an interface.
The first one is fine b/c you're making a new 150 that's of type Ford, its superclass.
Same argument for why the second one is true.
 

MSCoder610

Senior member
Aug 17, 2004
831
0
71
I agree that the first and second should work... why not write up a little test program like Rayden did.
 

th3dumbguy

Senior member
Feb 4, 2005
242
0
0
alright thnx guys for the help. did anyone take it today? some of my friends said it was fairly easy and they were surprised i didnt take it.
 

Rayden

Senior member
Jun 25, 2001
790
1
0
I am in college now. So no AP for me. Actually I was homeschooled so I never took any AP tests. Why bother when I was taking college classes instead?
 

shuan24

Platinum Member
Jul 17, 2003
2,558
0
0
since when did AP computer science test over java? I was thinking it should be c or c++...
 

eLiu

Diamond Member
Jun 4, 2001
6,407
1
0
Originally posted by: shuan24
since when did AP computer science test over java? I was thinking it should be c or c++...

last year was the first year it was in java. before that it had been cpp for some time; it was pascal before then

but yeah the way the AP does java is just retarded...
 

Rayden

Senior member
Jun 25, 2001
790
1
0
Java makes more sense than C++. But it is kinda ridiculous to test only one language since people learn different ones.