Java MCQ: Which keyword is used to inherit a class in Java?
a) implement
b) extends
c) inherits
d) derived
Answer:
b) extends
Explanation:
The keyword extends
in Java is used to inherit a class, meaning that it allows one class to take on the properties and methods of another. This is a key feature in object-oriented programming, promoting code reuse.
When a class extends another, it can use the fields and methods of the parent class, as well as add its own. This relationship forms a class hierarchy, where the subclass inherits behavior from the superclass.
This inheritance mechanism allows developers to create more complex and flexible systems, building on existing code without having to rewrite it from scratch.
Reference links:
https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html