• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Aaron
 
reply
    Bookmark Topic Watch Topic
  • New Topic