Multilevel Inheritance
Inheritance in Java Syntax with Example:
Inheritance in Java is a mechanism where
one class (child/subclass) acquires the
properties and behaviors (fields and
methods) of another class
(parent/superclass). It promotes code
reusability and establishes a parent-child
relationship between classes.
what is Multilevel Inheritance: ?
Code :
Multilevel inheritance in Java refers to a
scenario where a class inherits from
another class, which itself is derived from
another class. This creates a chain of
inheritance where properties and methods
of all ancestor classes are accessible to the
child class.
Why it is used ?
1. Code Reusability: Allows reusing code
written in the parent class, reducing
redundancy.
2. Extensibility: New functionality can be
easily added to existing classes without
modifying them.
3. Maintainability: Centralized code makes
maintenance easier by updating the
parent class instead of every child
class.
4. Method Overriding: Enables
polymorphism by allowing subclasses
to provide specific implementations for
parent methods.
5. Better Organization: Promotes logical
hierarchy and clear relationships among
classes.
Name&Rollno: Syed Rehan Ali, D03