extends keyword in java

The ” extends ” 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.

In other words,
When declaring a class/interface as a subclass of another class/interface, the extends keyword is used.

Example

1
2
3
4
5
6
7
8
9
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

1
2
3
4
5
6
7
8
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.

About the Author

Karibasappa G C (KB)
Founder of javainsimpleway.com
I love Java and open source technologies and very much passionate about software development.
I like to share my knowledge with others especially on technology 🙂
I have given all the examples as simple as possible to understand for the beginners.
All the code posted on my blog is developed,compiled and tested in my development environment.
If you find any mistakes or bugs, Please drop an email to kb.knowledge.sharing@gmail.com

Connect with me on Facebook for more updates

Share this article on