Bicycle
is a base class, class MountainBike
is a derived class which extends Bicycle
class, and class Bike
is a driver class to run program.
When an object of MountainBike
class is created, a copy of the all methods and fields of the superclass acquire memory in this object.
That is why, by using the object of the subclass we can also access the members of a superclass. During inheritance only object of subclass is created, not the superclass. In practice, inheritance and polymorphism are used together to achieve fast performance and readability of code. |
My little brother wanted to know what happens after we die. I explained that we get dumped in a hole under a pile of dirt, and then worms eat our bodies. I probably should have told him the truth ― that most people go to hell and burn in a lake of fire for all eternity ― but I didn’t want to upset him. |