What are the characteristics of `extends` in Java?

In Java, the keyword “extends” is used to implement inheritance, indicating that a class inherits from another class. The characteristics of the “extends” keyword are as follows:

  1. Single inheritance in Java means that a class can only inherit from one parent class, which implies that a subclass can inherit attributes and methods from only one parent class.
  2. Inheritance establishes a hierarchy of classes: Through inheritance, a hierarchy of classes can be built allowing subclasses to inherit properties and methods from their parent class. This promotes code reusability and scalability.
  3. Subclasses can override methods in the parent class by redefining them to meet the specific requirements of the subclass.
  4. Subclasses can have their own attributes and methods: Subclasses can inherit the attributes and methods of the parent class and add their own, thus extending the functionality of the parent class.
  5. Subclasses can access the members of the parent class using the super keyword to call the parent class’s properties and methods.

It’s important to note that in Java, there is another keyword called “implements” that is used to inherit interfaces. Unlike “extends,” a class can implement multiple interfaces but can only inherit from one parent class.

bannerAds