This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA 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