Different objects in one way or the other relate.Just like Vehicles,there are different type of cars,like 2wheeldrive,fourwheel drive,3...
Different
objects in one way or the other relate.Just like Vehicles,there are different
type of cars,like 2wheeldrive,fourwheel drive,3wheels.All these vehicles share
one common thing,they all have steering wheel,they all have wheels,brakes
etc.But some cars will have additional features like Turbo charged,leather
seats,two exhaust fumes.
Inheritance
allows classes to inherit state and behavior that are common.Think of class
Subaru cars that inherits its state and behavior from superclass Vehicles.
How to create a Child class or subclass
Superclass
/** * * @author Eric * Site:www.techoverload.net * Date:10/26/2017 */ public class Vehicle { public void changeGear() { } }
Subclass
/** * * @author Eric * Site:www.techoverload.net * Date:10/26/2017 */ class SubaruCars extends Vehicle { void turboCharged() { } }