• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

casting

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am preparing for JCP 1.4 and I saw a question in Boone's mock exam, the code of which is as follows:
class A{}
class B extends A{}
class c extends B{}
A a = new A();
B b = new B();
C c = new C();
Now it says that this statement is illegal.
b=(B)c;
Can anyone tell me why it is illegal to cast an object reference and assign it.
Thnaks a lot
Latha
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure you copied that out of the book correctly. As it is, the statement you identified is perfectly legal. Try it and see - it compiles fine. Check the book again and see if you read that correctly. If you have, you might want to check the errata on the book and see if that problem has been noted.
reply
    Bookmark Topic Watch Topic
  • New Topic