Java extends keyword example
- Details
- Written by Nam Ha Minh
- Last Updated on 19 August 2019   |   Print Email
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:
- 9 Rules about Constructors in Java
- 12 Rules and Examples About Inheritance in Java
- 12 Rules of Overriding in Java You Should Know
- 10 Java Core Best Practices Every Java Programmer Should Know
- Understand Interfaces in Java
- Understand how variables are passed in Java
- Understand encapsulation in Java
Comments