CHAPTER 15
Beginner
Inheritance in Java
Updated: May 17, 2026
5 min read
# CHAPTER 15
Inheritance in Java
1. Introduction
Inheritance allows a class to acquire the properties and methods of another class. It's one of the most powerful features of OOP, enabling code reuse and establishing natural hierarchies — just like how a child inherits traits from a parent.2. Learning Objectives
-
Use the
extendskeyword.
- Understand single, multilevel, and hierarchical inheritance.
-
Use the
superkeyword.
- Override methods.
- Understand the IS-A relationship.
3. The extends Keyword
java
4. Types of Inheritance in Java
Note: Java does NOT support multiple inheritance with classes (a class cannot extend two classes). Use interfaces instead.
5. The super Keyword
Access parent class members from a child class:
java
6. super() in Constructors
java
7. Method Overriding
A child class provides its own implementation of a parent method:
java
8. The @Override Annotation
Tells the compiler you intend to override a parent method. If you make a typo, the compiler catches it:
java
9. The final Keyword with Inheritance
-
final class— Cannot be extended.
-
final method— Cannot be overridden.
java
10. MCQ Quiz with Answers
Question 1
Which keyword establishes inheritance?
Question 2
Java supports multiple inheritance via:
Question 3
super() must be:
Question 4
Method overriding means:
Question 5
Which annotation marks an overriding method?
Question 6
Can a final class be extended?
Question 7
What does super.method() do?
Question 8
If no constructor is defined in child, what happens?
Question 9
IS-A relationship in inheritance means:
Question 10
Can a child class add new methods?
11. Interview Questions
- Q: Why doesn't Java support multiple inheritance with classes?
- Q: What is the diamond problem?
- Q: Difference between method overloading and overriding?
- Q: When should you use inheritance vs composition?
12. Summary
Inheritance allows code reuse through parent-child relationships usingextends. super accesses parent members. Method overriding lets children customize inherited behavior. Java avoids multiple class inheritance to prevent the diamond problem, but supports it through interfaces.