Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Javaranch question

 
Parimala Somasundaram
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>
> I'm not sure about the answer to question#24 in the rules round up game. It
> is as follows:
>
> Q: Class Y is a subclass of class X. Will this compile? Y myY=new X()?
>
> Ans: No
>
> Is it not true that though the code is incorrect, referencing an object of
> class X using a reference of subclass Y, it will fail only at runtime and not
> at compile time?
>
 
Sean Casey
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code will not compile. the rules roundup game is correct. Try it for yourself.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic