File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Javaranch question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Javaranch question" Watch "Javaranch question" New topic
Author

Javaranch question

Parimala Somasundaram
Ranch Hand

Joined: Mar 31, 2001
Posts: 41
>
> 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

Joined: Dec 16, 2000
Posts: 625
The code will not compile. the rules roundup game is correct. Try it for yourself.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Javaranch question