Abstract Classes : Abstract Class « Class Definition « Java Tutorial






  1. Provide a contract between a service provider and its clients.
  2. An abstract class can provide implementation.
  3. To make an abstract method, use the abstract modifier in front of the method declaration.
public abstract class DefaultPrinter {
  public String toString() {
    return "Use this to print documents.";
  }

  public abstract void print(Object document);
}
  1. The toString method has an implementation, so you do not need to override this method.
  2. The print method is declared abstract and does not have a body.
public class MyPrinter extends DefaultPrinter {
  public void print(Object document) {
    System.out.println("Printing document");
    // some code here
  }
}








5.28.Abstract Class
5.28.1.Abstract Classes
5.28.2.A demonstration of abstract.
5.28.3.Using abstract methods and classes.