What is inheritance
Child object behave a parent object
Keyword - Extends
Inheritance in Java enables a class to inherit properties and actions from another class, called a superclass or parent class. A class derived from a superclass is called a subclass or child group. Through inheritance, a subclass can access members of its superclass (fields and methods), enforce reuse rules, and encourage hierarchy.
TYPES OF INHERITANCE
1.Single inheritance
2.Multilevel inheritance
3.Hierarchical inheritance
4.Hybrid inheritance
5.Multiple inheritance (java is not support)
Single inheritance
Single inheritance in Java allows a class (subclass/child class) to inherit properties and behaviors from only one parent class (superclass/base class). This is the most fundamental form of inheritance in Java, promoting code reusability and organization. The child class inherits all accessible methods and fields from the parent, and can then add its own specific methods and fields.
Key Concepts:
**
**Parent Class (Superclass/Base Class): The class from which a subclass inherits.
Child Class (Subclass/Derived Class): The class that inherits from a parent class.
extends keyword: Used to indicate that one class inherits from another.
Inheritance: The process of a class inheriting properties and methods from another class.
Multilevel inheritance
Multilevel inheritance in Java occurs when a class inherits from a class, and then another class inherits from that derived class.
Hierarchical inheritance
Hierarchical inheritance in Java is a type of inheritance where a single parent class is extended by multiple child classes. Each child class inherits the properties and methods of the parent class but can also define its own unique features.
Hybrid inheritance
Hybrid inheritance in Java occurs when a combination of two or more types of inheritance is within a single class hierarchy. Java supports multiple inheritance using interfaces and single inheritance through classes.
Multiple inheritance
Multiple inheritance in Java refers to a scenario where a class can inherit properties and methods from more than one superclass. However, Java does not support multiple inheritance directly through classes due to the complexity and ambiguity it can cause.