Inheritance provides a powerful and natural mechanism for organizing and structuring software.Classes inherit state and behavior from their superclasses, and explains how to derive one class from another using the simple syntax provided by the Java programming language. In object-oriented programming, inheritance is a way to form new classes (instances of which are called objects) using classes that have already been defined.
The new classes, known as derived classes, take over (or inherit) attributes and behavior of the pre-existing classes, which are referred to as base classes (or ancestor classes). It is intended to help reuse existing code with little or no modification.
An advantage of inheritance is that modules with sufficiently similar interfaces can share a lot of code, reducing the complexity of the program. Inheritance therefore has another view, called polymorphism, which describes many pieces of code being controlled by shared control code. Inheritance is typically accomplished either by overriding (replacing) one or more methods exposed by ancestor, or by adding new methods to those exposed by an ancestor.
For example :
We can inherit all properties of a vehicle, like wheels, engine etc. to an object car. That means a "car is a vehicle". Car will have all the properties of a vehicle plus some unique features.
For example :
We can inherit all properties of a vehicle, like wheels, engine etc. to an object car. That means a "car is a vehicle". Car will have all the properties of a vehicle plus some unique features.
Next : Access Specifiers In Object Oriented Programming