Which keyword is used by a Java class to inherit from another class?
2024
Which keyword is used by a Java class to inherit from another class?
Answer: A. extends — ConceptIn Java, class-to-class inheritance creates a subclass–superclass relationship. A subclass declaration names its direct superclass with the keyword…
- A.
extends
- B.
inherits
- C.
implements
- D.
More than one of the above
- E.
None of the above
Attempted by 718 students.
Show answer & explanation
Correct answer: A
Concept
In Java, class-to-class inheritance creates a subclass–superclass relationship.
A subclass declaration names its direct superclass with the keyword extends.
Application
For example,
class Child extends Parent {}declaresChildas a subclass ofParent.Childcan inherit the accessible fields and methods ofParent.
Contrast and cross-check
implementsconnects a class to one or more interfaces; it does not name a superclass.inheritsis an English verb used to describe inheritance, not Java declaration syntax.The set choices “More than one of the above” and “None of the above” do not apply because one listed keyword has the specified class-to-class role.
Therefore, the required keyword is extends.