• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Inheritence

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is from Dan's site

And the answer is f, and the reason given is that


Although line 12 appears to be the source of a compiler error it is not. In line 12, the reference named base actually refers to an object of type Sub. Therefore, the reference to the object may be cast to type Sub.


which is quite logical. But i guessed the answer to be line 10: I1 i1 = s1;
because i thought that i1 and s1 have no direct hierarchy between them.
But seems like since base implements i1 and then sub extends base, s1 can be assigned to i1.
Is this correct?
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes its correct.
Sub extends Base which implements interface I1.
Hence Sub indirectly implements I1,and is therefore a supertype.
A supertype reference can be assigned a subtype reference and so no compiler error.
Chitra
 
I AM MIGHTY! Especially when I hold this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic