This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes changing reference types Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "changing reference types" Watch "changing reference types" New topic
Author

changing reference types

Neha Mittal
Greenhorn

Joined: Dec 05, 2008
Posts: 10
What does this mean -> "Although a reference variable's type can't be changed, it can be used to refer to an object whose type is a subtype of its own" ?


Dreams are not which you see when you are asleep. Dreams are that that do not let you sleep..
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36598
    
  16
You can have a reference to a Vehicle. You can use that reference to point to a Car object or a Bus object.
Aum Tao
Ranch Hand

Joined: Feb 14, 2006
Posts: 210
This is referring to inheritance. Consider the following example:


Taking your case, the Animal reference can be assigned to the Dog object, since it satisfies the IS A relationship. However, this fails for the second assignment since Shape doesn't extend Animal. Moreover, it shouldn't since they are not logically related.


SCJP 1.4 85%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: changing reference types
 
Similar Threads
overLoading
reference problem
classCastException
About type and class attribute of jsp usebean
arrays & final