• 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

Object Casting

 
Greenhorn
Posts: 19
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SuperClass Cannot be Cast to SubClass why ?
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
because every Car is a Vehicle but not all Vehicles are cars
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SuperClass can not be casted to subclass, because subclass contains more features then superclass, and when you try this, subclass needs all the details to become a complete object while superclass provides only the basic details , so as a result it is not allowed.

e.g

Every Car has engine , but not all the cars have cruise-tonic system, so when you try to convert a superCar into subCar, subCar will require cruise-tonic system , while it will no t be provided, so as a result subCar can not be completed,

So that's why in programming languages it is not allowed to avoid post casting problems of objects.

:-)

Regards,
Safdar Khan
 
reply
    Bookmark Topic Watch Topic
  • New Topic