Java MCQ: Which of the following is true about inheritance in Java?
Answer:
Explanation:
Inheritance in Java is a mechanism where one class (the subclass) inherits fields and methods from another class (the superclass). This promotes code reuse and establishes a natural hierarchy between classes. The subclass can also override methods from the superclass to provide specific implementations.
Java does not support multiple inheritance through classes, meaning a class cannot inherit from more than one class. However, Java does support multiple inheritance through interfaces, allowing a class to implement multiple interfaces.
The extends
keyword is used to inherit from a class, while the implements
keyword is used to implement interfaces. Understanding inheritance is key to building flexible and maintainable object-oriented systems in Java.
Reference links:
https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html