Question
Explain the concept of Inheritance in Java. Describe the different types of inheritance supported by Java (single, multilevel, hierarchical) and explain why Java does not support multiple inheritance through classes. How is this limitation overcome using interfaces?
Answer :
Word Count : 1376
_________ ________ _____ _________ ______ ____ __________.
_________ _________ ___ ______ _____ ____ _____ _____ __________ ______ __________ _________.
_______ ____ _____ __________ _____ ____ _________.
________ ________ _______ _______ _________ ____ _______ ________ _____ _______.
___ _____ ________ ___ _____ __________ _______ ____.
___ _______ _____ _________ _____ ______ ____ _____ _____ ________.
__________ ________ _________ _________ ________ __________ _____ ____ ________.
______ _______ _________ _________ _________ ____ __________ _______ ________ ____ ______ _____.
_____ _____ ____ ___ ______ _______ ______ ____ _______ _____ _____.
__________ _______ _____ ___ ____ _____ ____ __________.
______ ______ ________ ___ ____.
______ ___ ________ ________ _________.
_____ _______ ____ ________ ________ ____ ____ __________ _____ ____ _______ __________.
___ _____ __________ __________ ____ _______ ___ ____ ___ ___ _________ ______.
______ ________ __________ _____ _______ ________ _______ ______ __________ _________.
__________ ______ ___ ________ ______ ___ _________ ___ _____ _____ ____ __________.
_____ _______ _____ _____ ______ _______.
______ _______ ____ ______ __________ _____ ___.
__________ ______ _________ __________ ________ _________ _______ _______ _________.
_____ ________ _______ ________ _________.
_______ ____ ____ _____ _____ ___ ___ ____ ___ ______ _________ _________.
___ ______ _____ _____ ____ _____ ____ _________ ___ _____ ____.
_______ ___ __________ ______ ______ _________ ________.
__________ ____ ________ ____ ___.
____ _____ _____ __________ ______.
______ _________ _________ _________ ______ ______ ______ _________.
_________ ____ ____ ____ _______ ________ ________ ____ ______.
__________ _________ _________ ___ ______ ________.
_______ ___ ______ ______ _______ _______ ______ ______ _________ _____.
_________ _________ _________ _______ _____ _____ ____ ___ ____ _________ ________ ___.
___ _____ ____ _____ _____ __________.
_________ _____ _______ _________ _________ ___ __________ __________.
______ ________ _____ __________ __________ _________ __________ ________.
______ ___ _________ _______ ________ _____.
__________ ______ ____ _______ ______ ___.
_________ _____ _______ ________ ______ _______ _____ _________ ________ __________.
______ ________ ____ __________ _______ ________ ______.
_____ _______ ________ ______ ____ _________ _______ _________ _______ ________.
_________ __________ __________ ________ __________ ______ ________.
_______ ____ __________ ______ _____ ____ _______ ____ ______.
_____ __________ ____ ________ _______ ________ ________.
__________ ____ _________ __________ ________ _________ _______ _________ ____ _______ ________ ____.
______ _____ ________ _______ ____ ________ __________ __________ ____ ______ __________.
________ ____ _____ __________ _____ _________.
________ _________ _________ ______ ________ _________ _________ ______.
__________ ______ _____ ___ ______ ________ _______ __________ ______ _________ ____.
_______ __________ _________ _______ ______ ___ ______ ___ _____.
________ ____ ___ ___ ____ ____ ___.
__________ _________ _______ _______ ____ _________ ____ _________ ________ _______ _____ _________.
___ _________ _______ ___ ___ _____ _________ _____ _____.
______ _________ ___ _______ ______ _______ _______ ________.
_____ __________ _______ _____ _____ _________.
__________ ____ ________ ____ __________ _________ _________ _________ ______ _____ ____ _______.
___ _______ _____ ____ _____ ____ ____ ______ ______ ____.
_______ _____ ___ __________ ________ ________ ________ ____.
_______ ___ _____ ___ ____ _______ ________ _____ ___ _______ _______ ___.
______ __________ ____ _____ ________ ______ ____ ____ _______.
______ ______ _________ ________ ______ _________ ______ __________.
_______ __________ _______ _______ ____ ________ ___ _____ _____ __________ ________.
________ __________ ____ ________ ________ ______ ____ _______.
________ ___ __________ ____ ______ _______ __________ ____ _________ ________ ____ ____.
________ ___ _________ ____ _______ _______ ________ __________.
__________ _____ _____ ________ ____ __________.
________ ____ _________ ________ ______ ______ ________.
_________ _______ _________ _____ __________ _____ ___.
____ _______ _______ __________ ________ ______ _________ ______ ______.
_________ _______ ____ _____ ____ _______ __________ _____ ______ _____ _________.
________ __________ _____ ______ _______.
____ __________ _____ _____ ____ _______ ___ ____.
______ ______ _______ ___ _________ ____ _________ ____ ___ ________ ________.
_______ ___ ___ _______ ______ __________.
_________ ____ _____ ________ __________ __________.
__________ ____ ___ ___ ________ __________ _______ _________ ______ ______.
___ _________ _________ ________ _____ _____ ______ _______ ____ _________ ____ _________.
_________ _______ _________ ________ ___ _____ ____ ______ ______ _________ ______.
_____ __________ _____ _____ __________ ____.
___ ________ ______ ______ ______.
______ ________ ________ ______ _______ ________ __________.
______ __________ ______ __________ _______ _________ ________ ________ ______.
__________ _____ ________ _____ _________ __________ ____ _______ ____ ____.
________ ________ _______ ______ __________ ______ ______ _________.
__________ ___ ___ ___ _______ _________ ______ _____.
______ __________ ___ ____ ___ ___ ___.
_____ ___ __________ ____ ______ __________ _______.
_____ ________ ____ __________ __________ ______ _________ ___ ___ _______.
___ _______ ________ __________ __________ _________ _______ _________ _________ ______ ______ ________.
________ ____ __________ ________ ______ ______ __________ __________ __________.
________ ______ _____ __________ ____ ____ _______ ______ _________ ____ _____ ________.
____ _____ _____ ______ _____.
________ ________ ____ __________ ________.
_______ ____ ______ _______ _______ _______ ____ __________ _____ ___.
_______ ____ _____ _____ ________ __________ _______ ______ _________ _______ __________.
______ _______ ____ _____ ______.
______ _______ ______ _____ _______ ___ ________ ______ ______ _____.
______ _______ _______ _____ __________ _________ _________ ___.
______ _________ ___ _____ ______ __________ __________ ______ ______.
_________ _____ ________ __________ ______ __________ ______.
_______ ________ ____ ______ ________ _______ _________ ______ __________ ___.
____ ________ __________ ______ _______ ______ ______ ___.
_______ ____ _______ ________ ____ _______.
______ _________ __________ __________ __________ _______.
______ ______ ___ ___ ______ ____ _______.
_________ ____ ____ _________ __________ _____ ____ _______ __________ _________ ____.
___ ________ ______ ______ _____ _______ _____ _________ ____.
________ ________ _____ _______ ___ _____ ______ _______ ________ ______.
_____ ________ ______ ____ _____ ______.
_______ ___ _____ __________ _________.
__________ ___ _____ _______ __________ ___.
_____ ______ ________ ________ ____ _______ __________ ____ ____.
__________ ___ _____ ______ _________ __________ _________.
___ ________ ________ ____ ______ ________ ____ ________.
____ __________ _____ ______ ______ _____ _________ ____ __________ ____.
______ ______ ___ ________ _____ ____ ________.
____ ___ ____ ______ _______ __________ ______ _______ ________ __________.
_______ ________ _____ _________ ____.
_________ _____ __________ _________ _____ ________ _________ ________ _____ ____ _____ _____.
______ __________ ____ _____ ________ _________ ___ _______ ________ _______.
__________ _________.
Skip in 10
# Inheritance in Java Inheritance is one of the most important concepts of Object-Oriented Programming (OOP) and is used extensively in Java programming. It is a mechanism through which one class can acquire the properties and behaviours of another class. The class whose properties are inherited is called the superclass, parent class, or base class, while the class that inherits those properties is called the subclass, child class, or derived class. In Java, inheritance is mainly achieved using the `extends` keyword for classes. The main purpose of inheritance is to promote code reusability, reduce duplication, support method overriding, and establish a relationship between classes. For example, suppose there is a class called `Animal` containing common properties and methods such as `name`, `age`, and `eat()`. A class called `Dog` can inherit from `Animal` and use its properties and methods without defining them again. ```java class Animal { void eat() { System.out.println("Animal eats"); } } class Dog extends Animal { void bark() { System.out.println("Dog barks"); } } ``` In this example, `Dog` is a subclass of `Animal`. Therefore, an object of `Dog` can access the `eat()` method inherited from `Animal`, as well as its own `bark()` method. ```java Dog d = new Dog(); d.eat(); d.bark(); ``` Inheritance represents an "is-a" relationship. A dog is an animal, so `Dog` can inherit from `Animal`. Java inheritance therefore helps programmers model real-world relationships in a structured manner. Inheritance also supports method overriding. When a subclass provides its own implementation of a method that already exists in its superclass, it is called method overriding. This is an important feature for achieving runtime polymorphism. ```java class Animal { void sound() { System.out.println("Animal makes a sound"); } } class Dog extends Animal { @Override void sound() { System.out.println("Dog barks"); } } ``` Here, the `Dog` class changes the implementation of the `sound()` method inherited from `Animal`. When the method is called using a `Dog` object, the overridden version is executed. Java supports several forms of inheritance through classes, particularly single inheritance, multilevel inheritance, and hierarchical inheritance. Single inheritance occurs when one subclass inherits directly from one superclass. It is the simplest form of inheritance. ```java class Vehicle { void start() { System.out.println("Vehicle starts"); } } class Car extends Vehicle {
_____ __________ ______ ___ ___ __________ ______ ___._________ ________ _____ _________ ______ ____ __________.
_________ _________ ___ ______ _____ ____ _____ _____ __________ ______ __________ _________.
_______ ____ _____ __________ _____ ____ _________.
________ ________ _______ _______ _________ ____ _______ ________ _____ _______.
___ _____ ________ ___ _____ __________ _______ ____.
___ _______ _____ _________ _____ ______ ____ _____ _____ ________.
__________ ________ _________ _________ ________ __________ _____ ____ ________.
______ _______ _________ _________ _________ ____ __________ _______ ________ ____ ______ _____.
_____ _____ ____ ___ ______ _______ ______ ____ _______ _____ _____.
__________ _______ _____ ___ ____ _____ ____ __________.
______ ______ ________ ___ ____.
______ ___ ________ ________ _________.
_____ _______ ____ ________ ________ ____ ____ __________ _____ ____ _______ __________.
___ _____ __________ __________ ____ _______ ___ ____ ___ ___ _________ ______.
______ ________ __________ _____ _______ ________ _______ ______ __________ _________.
__________ ______ ___ ________ ______ ___ _________ ___ _____ _____ ____ __________.
_____ _______ _____ _____ ______ _______.
______ _______ ____ ______ __________ _____ ___.
__________ ______ _________ __________ ________ _________ _______ _______ _________.
_____ ________ _______ ________ _________.
_______ ____ ____ _____ _____ ___ ___ ____ ___ ______ _________ _________.
___ ______ _____ _____ ____ _____ ____ _________ ___ _____ ____.
_______ ___ __________ ______ ______ _________ ________.
__________ ____ ________ ____ ___.
____ _____ _____ __________ ______.
______ _________ _________ _________ ______ ______ ______ _________.
_________ ____ ____ ____ _______ ________ ________ ____ ______.
__________ _________ _________ ___ ______ ________.
_______ ___ ______ ______ _______ _______ ______ ______ _________ _____.
_________ _________ _________ _______ _____ _____ ____ ___ ____ _________ ________ ___.
___ _____ ____ _____ _____ __________.
_________ _____ _______ _________ _________ ___ __________ __________.
______ ________ _____ __________ __________ _________ __________ ________.
______ ___ _________ _______ ________ _____.
__________ ______ ____ _______ ______ ___.
_________ _____ _______ ________ ______ _______ _____ _________ ________ __________.
______ ________ ____ __________ _______ ________ ______.
_____ _______ ________ ______ ____ _________ _______ _________ _______ ________.
_________ __________ __________ ________ __________ ______ ________.
_______ ____ __________ ______ _____ ____ _______ ____ ______.
_____ __________ ____ ________ _______ ________ ________.
__________ ____ _________ __________ ________ _________ _______ _________ ____ _______ ________ ____.
______ _____ ________ _______ ____ ________ __________ __________ ____ ______ __________.
________ ____ _____ __________ _____ _________.
________ _________ _________ ______ ________ _________ _________ ______.
__________ ______ _____ ___ ______ ________ _______ __________ ______ _________ ____.
_______ __________ _________ _______ ______ ___ ______ ___ _____.
________ ____ ___ ___ ____ ____ ___.
__________ _________ _______ _______ ____ _________ ____ _________ ________ _______ _____ _________.
___ _________ _______ ___ ___ _____ _________ _____ _____.
______ _________ ___ _______ ______ _______ _______ ________.
_____ __________ _______ _____ _____ _________.
__________ ____ ________ ____ __________ _________ _________ _________ ______ _____ ____ _______.
___ _______ _____ ____ _____ ____ ____ ______ ______ ____.
_______ _____ ___ __________ ________ ________ ________ ____.
_______ ___ _____ ___ ____ _______ ________ _____ ___ _______ _______ ___.
______ __________ ____ _____ ________ ______ ____ ____ _______.
______ ______ _________ ________ ______ _________ ______ __________.
_______ __________ _______ _______ ____ ________ ___ _____ _____ __________ ________.
________ __________ ____ ________ ________ ______ ____ _______.
________ ___ __________ ____ ______ _______ __________ ____ _________ ________ ____ ____.
________ ___ _________ ____ _______ _______ ________ __________.
__________ _____ _____ ________ ____ __________.
________ ____ _________ ________ ______ ______ ________.
_________ _______ _________ _____ __________ _____ ___.
____ _______ _______ __________ ________ ______ _________ ______ ______.
_________ _______ ____ _____ ____ _______ __________ _____ ______ _____ _________.
________ __________ _____ ______ _______.
____ __________ _____ _____ ____ _______ ___ ____.
______ ______ _______ ___ _________ ____ _________ ____ ___ ________ ________.
_______ ___ ___ _______ ______ __________.
_________ ____ _____ ________ __________ __________.
__________ ____ ___ ___ ________ __________ _______ _________ ______ ______.
___ _________ _________ ________ _____ _____ ______ _______ ____ _________ ____ _________.
_________ _______ _________ ________ ___ _____ ____ ______ ______ _________ ______.
_____ __________ _____ _____ __________ ____.
___ ________ ______ ______ ______.
______ ________ ________ ______ _______ ________ __________.
______ __________ ______ __________ _______ _________ ________ ________ ______.
__________ _____ ________ _____ _________ __________ ____ _______ ____ ____.
________ ________ _______ ______ __________ ______ ______ _________.
__________ ___ ___ ___ _______ _________ ______ _____.
______ __________ ___ ____ ___ ___ ___.
_____ ___ __________ ____ ______ __________ _______.
_____ ________ ____ __________ __________ ______ _________ ___ ___ _______.
___ _______ ________ __________ __________ _________ _______ _________ _________ ______ ______ ________.
________ ____ __________ ________ ______ ______ __________ __________ __________.
________ ______ _____ __________ ____ ____ _______ ______ _________ ____ _____ ________.
____ _____ _____ ______ _____.
________ ________ ____ __________ ________.
_______ ____ ______ _______ _______ _______ ____ __________ _____ ___.
_______ ____ _____ _____ ________ __________ _______ ______ _________ _______ __________.
______ _______ ____ _____ ______.
______ _______ ______ _____ _______ ___ ________ ______ ______ _____.
______ _______ _______ _____ __________ _________ _________ ___.
______ _________ ___ _____ ______ __________ __________ ______ ______.
_________ _____ ________ __________ ______ __________ ______.
_______ ________ ____ ______ ________ _______ _________ ______ __________ ___.
____ ________ __________ ______ _______ ______ ______ ___.
_______ ____ _______ ________ ____ _______.
______ _________ __________ __________ __________ _______.
______ ______ ___ ___ ______ ____ _______.
_________ ____ ____ _________ __________ _____ ____ _______ __________ _________ ____.
___ ________ ______ ______ _____ _______ _____ _________ ____.
________ ________ _____ _______ ___ _____ ______ _______ ________ ______.
_____ ________ ______ ____ _____ ______.
_______ ___ _____ __________ _________.
__________ ___ _____ _______ __________ ___.
_____ ______ ________ ________ ____ _______ __________ ____ ____.
__________ ___ _____ ______ _________ __________ _________.
___ ________ ________ ____ ______ ________ ____ ________.
____ __________ _____ ______ ______ _____ _________ ____ __________ ____.
______ ______ ___ ________ _____ ____ ________.
____ ___ ____ ______ _______ __________ ______ _______ ________ __________.
_______ ________ _____ _________ ____.
_________ _____ __________ _________ _____ ________ _________ ________ _____ ____ _____ _____.
______ __________ ____ _____ ________ _________ ___ _______ ________ _______.
__________ _________.
IGNOU ACADEMY
Your IGNOU journey, made easier.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
Continue Reading — It's Free
Sign in with Google to unlock more of this answer.
✓ Free access
✓ Unlock up to 60% of the answer
✓ No payment required
✓ Unlock up to 60% of the answer
✓ No payment required
Quick Google sign-in. No separate registration form.