Inheritance in Java - PPTX - 20241025 - 101324 - 0000
Inheritance in Java - PPTX - 20241025 - 101324 - 0000
Presented By :Group-1
⚬Pavani (230101120241)
⚬Pawan Kalyan (230101120243)
⚬Achhutha Reddy (230101120245)
⚬Rup Kumar (230101120277)
Inherit Members
The child class automatically inherits all non-private fields and
methods from the parent class, allowing for code reuse.
inheritance syntax
Types of inheritance
1. Single Inheritance
In single inheritance, a sub-class is derived from only one
super class. It inherits the properties and behavior of a single-
parent class. In the figure, ‘A’ is a parent class and ‘B’ is a
child class. The class ‘B’ inherits all the properties of the
class ‘A’.
2. Multilevel Inheritance
In Multilevel Inheritance, a derived class will be inheriting a
base class, and as well as the derived class also acts as the
base class for other classes.
In the image, class A serves as a base class for the derived class
B, which in turn serves as a base class for the derived class C. In
Java, a class cannot directly access the grandparent’s members.
3. Hierarchical Inheritance
In Hierarchical Inheritance, one class serves as a
superclass (base class) for more than one
subclass. In the image, class A serves as a base
class for the derived classes B, C, and D.
4. 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. In the image, Class C is derived from
interfaces A and B.
different terms in inheritance
• Keyword (extends)
1.Used to establish the inheritance relationship between classes.
2.The subclass inherits all non-private members of the superclass.
• Method Overriding
1.A subclass can provide a specific implementation for a method inherited
from its superclass.
2.The method signature (name, parameters, and return type) must be the
same.
3.The @Override annotation can be used to indicate method overriding.
• Method Overloading
1.A class can have multiple methods with the same name but
different parameters.
2.Method overloading is not directly related to inheritance but can be
used in conjunction with it.
Advantages of Inheritance
• Code Reusability: Reduces code duplication and promotes efficient
development.