Back to the 2023 paper

Module III: Basics of Web Programming

20232m

Explain Inheritance.

Worked SolutionAI Assisted

Inheritance is an OOP mechanism in which a new class (subclass or child) acquires the fields and methods of an existing class (superclass or parent). It promotes code reuse and models an is-a relationship.

class Animal {
    void eat() { System.out.println("eating"); }
}
class Dog extends Animal {
    void bark() { System.out.println("barking"); }
}
// Dog d = new Dog(); d.eat(); d.bark();

Types: single, multilevel, and hierarchical (Java supports multiple inheritance only through interfaces).

Benefits: reusability, easier maintenance, and method overriding for runtime polymorphism.

Similar questions

Budget AppAndroid App

Pocketly on Android

Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.