Inheritance - Java OOPs Concepts

Inheritance is another important concept in object oriented programming. 

Inheritance in Java

 is a mechanism by which one object acquires the properties and behaviors of the parent object. It’s essentially creating a parent-child relationship between classes. In Java, you will use inheritance mainly for code re-usability and maintainability.
Keyword “extends” is used to inherit a class in java. The “extends” keyword indicates that you are making a new class that derives from an existing class. In the terminology of Java, a class that is inherited is called a super class. The new class is called a subclass.
A subclass inherits all the non-private members (fields, methods, and nested classes) from its superclass. Constructors are not members, so they are not inherited by subclasses, but the constructorof the superclass can be invoked from the subclass.
e.g.
class Employee
{
    private Department department;
    private Address address;
    private Education education;
    //So on...
}
class Manager extends Employee {
    private List<Employee> reportees;
}
In above example, Manager is specialized version of Employee and reuses department, address and education from Employee class as well as define it’s own reportees list.


Thank you for sharing Your Knowledge with others who need It.-Team LetML

Post a Comment

Copyright © LetML. Blogger Templates Designed by OddThemes