Chapter 6 |
Abstract methods
Before we plunge into interfaces and abstract classes, we have a look at abstract methods.
An abstract method is a method that has a modifier, return type, and method signature followed by a semicolon. Abstract methods do not have bodies nor braces { }
. A few examples of abstract methods:
public abstract void eat(int grams); //abstract void method public abstract String bark(String dogName); //abstract return-type method
Remember: it is not possible to make an abstract
constructor or an abstract static
method!
Apart from abstract methods, it is possible to create abstract instance fields. Abstract instance fields cannot be initialized:
public String area; //abstract instance fields are not initialized
Chapter 6 |