Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent object.
The idea behind inheritance in java is that you can create new classes that are built upon existing classes. When you inherit from an existing class, you can reuse methods and fields of parent class, and you can add new methods and fields also
Inheritance represents the IS-A relationship, also known as parent-child relationship
Why use inheritance in java
For Method Overriding (so runtime polymorphism can be achieved).
For Code Reusability.
The extends keywordindicates that you are making a new class that derives from an existing class. In the terminology of Java, a class that is inherited is called a super class. The new class is called a subclass.
Output:
Programmer salary is:40000.0
Bonus of programmer is:10000
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
- For Method Overriding (so runtime polymorphism can be achieved).
- For Code Reusability.
The extends keyword indicates that you are making a new class that derives from an existing class.In the terminology of Java, a class that is inherited is called a super class. The new class is called a subclass.