• 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 ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Want to understand explicit type casting in Objects

Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have come across on OCA Study Guide by Jeane Boyarsky & Scott Selikoff;
I have been reading the polymorphism section.
I have been fully understanding up-casting and down-casting in primitives data types. if I try to apply my previous experience in type casting, which class is greater then the other if they are superclass and it's subclasses or interface and implementing abstracts & classes. and how some methods would not available in some objects.
I apologize in advance if my English seems poor
Posts: 76454
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As for “greater” and “smaller”: I would suggest you look in the Java┬« Language Specification (=JLS) and see what operators they use. You probably won't find the JLS easy to understand.

As you doubtless already know, casting to a supertype always works without risk of throwing an Exception. But there is hardly ever a need to cast upwards.You would not notice the difference if you take the cast away. Casting down is different; you cannot change the type of an object, but you can tell the compiler that it will be a particular type. The compiler will either see the cast is impossible…or see the cast is not impossible and it will then believe you implicitly until the runtime complains with an Exception.Down casts may be required, but they are risky and error‑prone and you should design your classes to avoid any need to cast downwards.
It's a beautiful day in this neighborhood - Fred Rogers. Tiny ad:
Garden Master Course kickstarter
    Bookmark Topic Watch Topic
  • New Topic