extends keyword in java
The ”
” keyword is used in a class or interface declaration to indicate that the class or interface being declared is a subclass of the class or interface whose name follows the extends keyword.extends
In other words,
When declaring a class/interface as a subclass of another class/interface, the extends
keyword is used.
Example
- public class Shape
- {
- }
- public class Rectangle extends Shape
- {
- }
public class Shape { } public class Rectangle extends Shape { }
In the above case, subclass “Rectangle” is extending “Shape” class using extends keyword
- interface Animal{
- }
- interface Reptile extends Animal
- {
- }
interface Animal{ } interface Reptile extends Animal { }
In the above case, interface “Reptile” is extending “Animal” interface using extends keyword
Class extending another class uses “extends” keyword.
Interface extending another interface uses “extends” keyword.