File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Is this explanation correct? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Is this explanation correct?" Watch "Is this explanation correct?" New topic

Is this explanation correct?

Jay Taylor

Joined: Jan 31, 2008
Posts: 6
This is taken from a practice test from uCertify application.

I cannot follow the logic and was feeling confused so I decided to seek assistance. Is the explanation provided accurate and if so.. How?

interface A1{}
interface A2 {}
class C1 implements A1 {}
class C2 implements A2 {}
class C3 extends C1 implements A2 {}
C1 object1;
C2 object2;
C3 object3;

Which of the following statements is legal in the context of the above code?
A� object3=object1;
B- object2=object1;
C- object3=object2;
D- A2 c = object1;
E- A1 a=object2;
F� A1 b=object3;

Explanation: Answer option F is correct.
The A1 b = object3; statement in legal, in which b is the reference variable of the interface A1, which is assigned to hold object3. Here, object3 is the reference variable of the class C3, which implements the interface A2 and inherits the class C1. The class C1 implements the A1 interface. Therefore, the class C3 also indirectly implements A1.
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2068
It tests your knowledge on polymorphism and inheritance.

You can think it this way.

I just replaced them with their class type.

A� C3=C1; Is C1 a C3? NO
B- C2=C1; Is C1 a C2? NO
C- C3=C2; Is C2 a C3? NO
D- A2=C1; Is C1 a A2? NO
E- A1=C2; Is C2 a A1? NO
F� A1=C3; Is C3 a A1? YES
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

This question is complex enough that I would draw a UML diagram to figure it out.
I agree. Here's the link:
subject: Is this explanation correct?
It's not a secret anymore!