Java MCQ: What is inheritance in Java?
a) A mechanism to create new classes from existing ones
b) A way to encapsulate data
c) A method of overloading
d) A way to convert data types
Answer:
a) A mechanism to create new classes from existing ones
Explanation:
Inheritance in Java is a mechanism that allows a new class (subclass) to inherit fields and methods from an existing class (superclass). This promotes code reuse and creates a natural class hierarchy.
Understanding inheritance is essential for building structured and reusable code, enabling the creation of complex systems with minimal code duplication.
Reference links:
https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html