In Jaava, when declaring a class as a subclass of another class, the extends keyword is used. Here is an example:

class A {
    
    int value;
    
    void doSomething() {
        
    }
}

class B extends A {
    
}

In the above example, class B is a subclass of class A. In other words, class A is a super class of class B. As a sub class, class B inherits (extends) variables and methods declared from class A.

The extends keyword is also used to make an interface extends another interface, for example:

interface Animal { }

interface Reptile extends Animal { }

Related keyword: class, interface and implements. See all keywords in Java.

 

Related Topics:

 

Other Recommended Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.



Add comment