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

Student FinanceWeb Platform

Pocketly — Personal Finance for Students

Keep your hostel and college expenses under control. Track accounts, log spending in seconds, and stay within your monthly budget.