Inheritance
Java Inheritance:
Definition:
Inheritance is an Object-Oriented Programming (OOP) concept that allows creating a new class (subclass) from an existing class (superclass).
Syntax:
Example:
Inheritance Types:
Single Inheritance:
One subclass extends one superclass.
Example:
Class A extends Class B
.
Multilevel Inheritance:
Subclass extends another subclass, creating a chain.
Example:
Class B extends Class A
andClass C extends Class B
.
Hierarchical Inheritance:
Multiple subclasses extend a single superclass.
Example:
Class B extends Class A
andClass C extends Class A
.
Multiple Inheritance:
One subclass extends multiple superclasses.
Note: Java does not support multiple inheritance directly.
Hybrid Inheritance:
Combination of two or more types of inheritance.
Last updated