Would someone explain the concept of casting objects in Java and the usage of a subclass in place of a superclass? Also the usage of a superclass in place of a subclass?
I have read a few books and online material but I just don't get this concept for some reason...
For example if a have this class structure where object is the base class and Vehichle extends the object class. Then if we have 2 additional classes "Car" which extends "Vehichle" and "Motorcycle" which also extends vehicle. How does the object casting work? When would an explict cast be needed? When would the cast be implicit?
Object | Vehicle | Car - Motorcycle