• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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
 
Does this tiny ad smell okay to you?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic