wood burning stoves 2.0
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes answer please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "answer please" Watch "answer please" New topic

answer please

josephine chen
Ranch Hand

Joined: Oct 29, 2002
Posts: 216
given classes MyBase and MySub such that MySub is a subclass of MyBase, which line(s) if any cause a compiler error? Which line(s) if any cause a ClassCastException...
1. MyBase objBase = new MyBase(); ok
2. MySub objSub = new MySub(); ok
3. objBase = objSub; ok
4. objSub = obj ??? consider obj is a object of class Object
5. objBase = (MyBase)objSub;??
6. objSub = (MySub)objBase;???
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Only line 4 causes compilation error, the rest of the lines are correct. Explicit cast is needed at line 4.
The line 4 could be modified as
objSub =(MySub) obj ;
I agree. Here's the link: http://aspose.com/file-tools
subject: answer please
It's not a secret anymore!