• Post Reply Bookmark Topic Watch Topic
  • New Topic

Object reference variable unwilling to be reset to a different object type  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand why the object reference variable 'a' cannot be recast from a thisA object reference to a thisB object reference.

Is it the case that once a reference variable is linked to a particular object type then it cannot switch object types later on.

I am facing the Java Associate Developer exam soon and I am just clearing up some issues in my head around object reference variable assignment,

John



 
Ranch Hand
Posts: 50
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java is statically typed. If you tell the compiler that variable foo is an A, even if it's a B, then it will only let you do stuff that A can do.

That is to say, that polymorphism is a runtime only phenomenon. At compile time everything is static.
 
John O'Donoghue
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Aaron
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!