What is the usage of “extend” in Java?

In Java, the keyword “extend” is used to create a subclass of a class. It allows a class to inherit the properties and methods of another class.

The usage of the extend keyword is as follows:

class Subclass extends Superclass {
    // subclass code
}

Subclass, also known as a child class, inherits the properties and methods of the superclass, also known as a parent class (or super class). The subclass can also add its own additional properties and methods.

Subclasses have the ability to override methods of the parent class, as well as extend or modify its behavior. Additionally, subclasses can access the public and protected members of the parent class, but not its private members.

The relationship of inheritance can create a hierarchy of classes, with the parent class being the more general class and the child class being the more specific class. This relationship makes code reuse and extension more convenient.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds