Correct option is A
In Java, inheritance is a fundamental object-oriented programming (OOP) concept that allows a class to inherit properties and methods from another class. The keyword
extends is used to implement inheritance in Java, enabling a subclass to inherit from a superclass. This promotes code reusability and establishes a hierarchical relationship between classes. Therefore, the correct answer is (a) extends.
Important Key Points:
1.
Inheritance in Java:
· Inheritance allows a class (subclass) to inherit fields and methods from another class (superclass).
· It promotes code reusability and establishes an "is-a" relationship between classes.
2.
Keyword extends:
· The extends keyword is used to create a subclass that inherits from a superclass.
· Example:
class Animal { }
class Dog extends Animal { }
· Here, Dog inherits from Animal.
2.
Other Keywords:
·
inherits: Not a valid keyword in Java.
·
implements: Used to implement interfaces, not inheritance.
Knowledge Booster:
·
Types of Inheritance in Java:
· Single inheritance: A class inherits from one superclass.
· Multilevel inheritance: A class inherits from a subclass, which in turn inherits from another superclass.
· Hierarchical inheritance: Multiple subclasses inherit from a single superclass.
· Java does not support
multiple inheritance (a class inheriting from multiple superclasses) to avoid complexity and ambiguity.
· The super keyword is used in Java to refer to the superclass's methods or constructors.
· Inheritance is a key feature of OOP, along with
encapsulation,
polymorphism and
abstraction.