Abstract classes

An abstract class is a class that is never instantiated. A modified ‘abstract’ is used on the class header to declare a class as an abstract class. An abstract class generally contains abstract methods though it doesn’t have to. The child class of an abstract class must override the abstract methods of the parent, or it will also be considered as an abstract class. Mainly abstract classes are used in design decisions; it helps in establishing common elements in a class that are too general to instantiate. Abstract classes are defined so that other classes can extend them and make them concrete by implementing the abstract methods.

Here is a code that shows how abstract classes are used in JAVA.

public abstract class InventoryItem {

public String description; 

        //display() - will be overridde

public String display() {return "dummy";}

}

Here ‘abstract’ keyword forbids us to create an instance of InventoryItem class.