What is inheritance in Java?

Inheritance is one of the powerful concept of Object Oriented Languages.
Inheritance is nothing but one class inherits members of other class. Its one of the way in which two classes can be related.
Inheritance provides one additional Access Specifier, which is protected. Members of class declared as protected can be accessed within the class, and within immediate derived class.

For example, when class B inherits from class A. Class A is called Base class, Super class or Parent class.
Class B is called Derived class, Sub class or Child class.

When Inherited all members of Base class are inherited to Derived class, except private members.
public, protected, default Members of Base class can be directly accessed in Derived class.

Below are keywords used for inheritance
1.extends
2.super
3.protected

When member has same name in Base and Derived class, Base class members can be accessed in Derived class using super. keyword.

You may also like to read:
How many types of inheritance in Java?
usage of super keyword?
Access specifiers with examples?

One thought on “What is inheritance in Java?”

Leave a Reply