What is Inheritance in Java-Inheritance allows classes to inherit state and behavior that are common
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.
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(subclass) from 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() { } }