0% found this document useful (0 votes)
12 views7 pages

20 June 2022

Inheritance allows a class to inherit data and behaviors from another class, known as its parent or super class. This is called an "is-a" relationship and allows for code reusability. A child or subclass inherits all public and protected members of the parent class. Inheritance in Java supports three types: single inheritance where a class inherits from one parent class; multi-level inheritance where a child class inherits from its parent and grandparent; and hierarchical inheritance where a parent class is inherited by multiple child classes.

Uploaded by

sandesh ahir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views7 pages

20 June 2022

Inheritance allows a class to inherit data and behaviors from another class, known as its parent or super class. This is called an "is-a" relationship and allows for code reusability. A child or subclass inherits all public and protected members of the parent class. Inheritance in Java supports three types: single inheritance where a class inherits from one parent class; multi-level inheritance where a child class inherits from its parent and grandparent; and hierarchical inheritance where a parent class is inherited by multiple child classes.

Uploaded by

sandesh ahir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Understanding Inheritance

⚫ Inheritance is the ability of a class inheriting data and


behaviors from another class.
⚫ It is also called “Is-A” relation.
⚫ The main advantage of inheritance is code reusability. ⚫ By
using "extends" keyword we can implement IS-A relationship.
⚫ After inheriting the complete functionality of super class Sub
class can access the super class methods with its reference
object.
Common Terminology:
Parent class – Child class
Base class - Derived class
Super class - Sub class
⚫ All the data and methods which were present in parent
class is by default available to child class, but the reverse
is not applicable.
⚫ Hence by using child class reference we can call
both parent and child class methods.
⚫ But by using parent reference we can call only methods
available in the parent class and we can't call child class
specific methods.
⚫ Parent class reference can be used to hold child class
object, but Child class reference cannot be used to hold
parent class object.
⚫ For all the java classes including predefined and user
defined classes Object class acts as the super class to be
precise java.lang.Object class is superclass of all
classes.
⚫ When a class extends another class, the subclass
inherits all the public and protected members of the
super class. The default members are inherited only in
the same package.
⚫ Constructors are not inherited in to the sub class during
inheritance, we can call the constructors of super class by
invoking super class object.
Types Of Inheritance:
⚫ Java supports ‘3’ types of inheritance.
1. Single Inheritance
2. Multi-Level Inheritance

3. Hierarchal Inheritance

Single Inheritance
⚫ Every java class by default inherits from “java.lang.Object” class. ⚫
By this extension only, every user object gets the behavior of real
Object.
⚫ Hence every java class exhibits by default “Single Inheritance”. ⚫
Single Inheritance enables a derived class(Sub class) to inherit
properties and behavior from a single parent class

Multi-Level Inheritance
⚫ Accessing the functionality of objects in more than
one level is called “Multi-Level Inheritance”.
⚫ Child class accessing the functionality of grand

parent.

Hierarchal Inheritance
⚫ Sharing the properties of object to multiple child
objects is called “Hierarchal Inheritance”.

You might also like