This article helps you understand what is abstract keyword in Java and how to use it in the Java programming language.
You know, the abstract keyword is used to declare a class or a method as abstract. An abstract class can have abstract methods which have to be implemented by its sub classes. An abstract method does not have concrete implementation or body, and must ends with a semicolon. The following example declares a class Car as abstract:
public abstract class Car { public abstract void drive(); }
The method drive() is also declared as abstract.
An abstract class:
An abstract method:
A class that extends the abstract Car class and implements its abstract method:
class PoliceCar extends Car { public void drive() { // drive faster than normal car } }
An abstract class has both abstract and non-abstract methods:
abstract class Airplane { public abstract void takeOff(); public void landing() { // landing smoothly } }
See all keywords in Java.