This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Object Reference Conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Object Reference Conversion" Watch "Object Reference Conversion" New topic
Author

Object Reference Conversion

Brian Nguyen
Greenhorn

Joined: Mar 19, 2002
Posts: 22
Hello,
Could some one please explain to me the following rules of object reference conversion:
- If Old Type is an interface and New Type is a class, then the New Type must be Object.
- If Old Type is an array and New Type is a class, then New Type must be Object.
Thank you very much.
Brian
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Look at the JLS, §5.5 Casting Conversion. It outlines all of the details about casting conversions. If you have any more questions, just let me know.
Corey


SCJP Tipline, etc.
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
Yes on both counts.


The new object reference must be a supertype of the old object reference. No class can be considered a supertype of an interface except for Object.
(If we have interface/classes A and B, and B is a subclass or subinterface of A either directly or though some intervening "layers" of classes/interfaces, then A is a supertype of B.)
Object arrays, and arrays of primitives are considered of type Object.
[ June 27, 2002: Message edited by: Anthony Villanueva ]
 
Consider Paul's rocket mass heater.
 
subject: Object Reference Conversion