1. SUPREME
KNOWLEDGE
FOUNDATION GROUP
OF INSTITUTIONS
N A M E : AYA N D A S
S U B J E C T : OBJECT ORIENTED PROGRAMMING
PA P E R C O D E : PCC-CS503
D E PA R T M E N T : C O M P U T E R S C I E N C E A N D E N G I N E E R I N G
U N I V E R S I T Y R O L L N O : 2 5 3 0 0 1 2 1 0 5 7
Y E A R : 3 R D Y E A R
2. INHERITANCE IN JAVA
What is Inheritance ?
Inheritance in Java is a mechanism in which one object acquires all the properties and behaviors of a
parent object. It is an important part of OOPS (Object Oriented programming system).
The idea behind inheritance in Java is that you can create new classes. that are built upon existing
classes. When you inherit from an existing class, you can reuse methods and fields of the parent class.
Moreover, you can add new methods and fields in your current class also.
Inheritance represents the IS-A relationship which is also known as a parent-child relationship.
3. IMPORTANT TERMINOLOGY:
• Super Class: The class whose features are inherited is known as superclass(or a base class or a
parent class).
• Sub Class: The class that inherits the other class is known as a subclass(or a derived class,
extended class, or child class). The subclass can add its own fields and methods in addition to the
superclass fields and methods.
• Reusability: Inheritance supports the concept of “reusability”, i.e. when we want to create a new
class and there is already a class that includes some of the code that we want, we can derive our
new class from the existing class. By doing this, we are reusing the fields and methods of the
existing class.
4. TYPES OF INHERITANCE IN JAVA
• Single Inheritance
• Multilevel Inheritance
• Hierarchical Inheritance
• Multiple Inheritance
• Hybrid Inheritance
5. • Single Inheritance: When a class inherits another class, it is known as
a single inheritance.or subclasses inherit the features of one superclass. Like,
Dog class inherits the Animal class, so there is the single inheritance.
• Multilevel Inheritance: When there is a chain of inheritance, it is known
as multilevel inheritance. In Multilevel Inheritance, a derived class will be
inheriting a base class and as well as the derived class also act as the base
class to other class.
TYPES OF INHERITANCE IN JAVA
6. • Hierarchical Inheritance: When two or more classes inherits a single class, or ne class
serves as a superclass (base class) for more than one subclass., it is known as hierarchical
inheritance. example, Dog and Cat classes inherits the Animal class, so there is hierarchical
inheritance.
• Multiple Inheritance: In Multiple inheritances, one class can have more than one superclass
and inherit features from all parent classes. Please note that Java does not support multiple
inheritances with classes. In java, we can achieve multiple inheritances only
through Interfaces.
• Hybrid Inheritance: It is a mix of two or more of the above types of inheritance. Since java
doesn’t support multiple inheritances with classes, hybrid inheritance is also not possible
with classes. In java, we can achieve hybrid inheritance only through Interfaces.
TYPES OF INHERITANCE IN JAVA