• Post Reply Bookmark Topic Watch Topic
  • New Topic

variables that point to variables of another type  RSS feed

 
Brian Storenson
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to learn about inheritance, but I am confused about the second line in the main method. Is the firstAnimal variable storing the address of the Cat object from previous statement?

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, line 14 is merely copying the object reference from one variable to another.

It's legal to have a Cat instance referenced as an Animal because a Cat is an Animal (because Cat extends Animal).
 
Brian Storenson
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! That makes sense now.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!