This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

changing reference types

 
Neha Mittal
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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" ?
 
Campbell Ritchie
Sheriff
Pie
Posts: 48952
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic