Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Is this explanation correct?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?


QUESTION:
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.
 
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question is complex enough that I would draw a UML diagram to figure it out.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic