Mega Code Archive

 
Categories / Java Tutorial / Class Definition
 

Abstract Classes

Provide a contract between a service provider and its clients. An abstract class can provide implementation. 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); } The toString method has an implementation, so you do not need to override this method. 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   } }