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 Example
When a class inherits another class, it is known as a single inheritance.
Multilevel Inheritance Example
When there is a chain of inheritance, it is known as multilevel inheritance.
Hierarchical Inheritance Example
When two or more classes inherits a single class, it is known as hierarchical
inheritance.
#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.