In Java, the extends
keyword is used in class declarations to specify that a class is a subclass of another class. The class being extended is called the superclass, and the class that extends it is called the subclass.
Here's an example of how to use the extends
keyword in a class declaration in Java:
public class Subclass extends Superclass { // subclass code here }
In this example, the Subclass
is a subclass of the Superclass
, and it has access to all of the members (fields and methods) of the Superclass
, as well as any protected members of the Superclass
.
The extends
keyword is used to create a class hierarchy in Java, where a subclass can inherit the characteristics of its superclass and add or override its own characteristics.