Inheritance in Java is a mechanism in which one object acquires all the
properties and behaviors of a parent object.
Inheritance represents the IS-A relationship which is also known as
a parent-child relationship.
Syntax:
class Subclass-name extends Superclass-name
{
//methods and fields
}
Why use inheritance in java?
For Method Overriding (So runtime polymorphism can be achieved).
For Code Reusability.
Types of inheritance in java
There are five types of inheritance in java single,
Multilevel, Hierarchical, Multiple, Hybrid and Inheritances.
Why multiple inheritance is not supported in java?
(Note: Multiple inheritance is not supported in Java through class.)
To reduce the complexity and simplify the language, multiple inheritance is
not supported in java.
Single Inheritance in Java
When a class inherits another class, it is known as a single inheritance.
Multilevel Inheritance in Java
When there is a chain of inheritance, it is known as multilevel inheritance.
Hierarchical Inheritance in Java
When two or more classes inherits a single class, it is known as hierarchical inheritance.
Multiple Inheritance in Java
Multiple Inheritance is the process in which a class inherits properties from more than one class.
Java doesn't support Multiple Inheritance, but we can use interfaces instead of classes.
Hybrid inheritance in Java
Hybrid inheritance in Java combines different types of inheritance, such as single, multilevel or hierarchical.
A class that inherits from another class can reuse the methods and fields of that class.
More...
#Tags: | Java | Java Keywords | Java Methods | Java Questions | Java FAQs | Java questions and answers |
*Disclaimer: We have published the above images and information for reference purpose only, for any changes on the content we refer to visit the Official Website to get the latest info.
NOTE: Free Career Hub Employees will not call any candidates towards Job Offer or Job assistance. We never charge any candidates for Jobs. Please be aware of fraudulent Calls or Emails.