Programming Languages Java Subjective
Sep 24, 2025

Explain the concept of inheritance in Java with an example.

Detailed Explanation
Inheritance is a mechanism where a new class (child/subclass) acquires properties and methods of an existing class (parent/superclass). It promotes code reusability. Example:\nclass Animal { void eat() { System.out.println("Eating"); } }\nclass Dog extends Animal { void bark() { System.out.println("Barking"); } }\nDog can use both eat() and bark() methods.
Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback