Inheritance in Java | Example
→ Inheritance is an important concepts of OOPs(Object Oriented Programming).
→ Inheritance represents the IS-A relationship which is also known as a parent-child relationship.
→ Inheritance inherit the features(fields and methods) of one class to another class.
→ Inherit the properties of a class use of extends keyword .
→ Inheritance is a mechanism in which one object acquires all the properties and behaviors of a parent object.
See in fig....
Full Example 1:
Types of inheritance in java
→ Threre are Three types of inheritance supported.
√NOTE: Multiple inheritance and Hybrid Inheritance is not supported in java
1) Single Inheritance
→ A class inherits another class, it is known as a single inheritance.
2) Multilevel Inheritance
→ There is a chain of inheritance, it is known as multilevel inheritance.
3) Hierarchical Inheritance
→ When two or more classes inherits a single class.
Q.) Why multiple inheritance is not supported in java?
→ To reduce the complexity and simplify the language, see a scenario example where A, B, and C are three classes. The C class inherits A and B classes. If A and B classes have the same method and you call it from child class object, there will be ambiguity to call the method of A or B class.
Compile Time Error