This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design 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
Posts: 48652
56
  • 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