Definition

Java abstract class

A Java abstract class is a predefined programming definition of common characteristics (methods and variables) of a Java class, a category of objects that contains one or more abstracted methods.

In Java and other object oriented programming (OOP) languages, objects and classes (categories of objects) may be abstracted, which means that they are summarized into characteristics that are relevant to the current program’s operation. This abstraction helps the efficiency of the programming as extraneous details are not constantly being referred to. To be platform-agnostic, Java code is compiled into class files that can be interpreted by any Java VM. The resulting class file can run on different machines once a compatible Java VM has been downloaded and installed for the OS platform.

Abstract classes may use abstract methods to define how similar categories of objects take different actions under similar conditions. These abstract classes require subclasses to further define attributes necessary for individual instantiation. Individual instances resulting from classes are objects.

The following code shows how the public abstract “animal” avoids repeating the same code with different variables for each animal:

public abstract Animal
{
   public void eat(Food food)
   {
        // do something with food.... 
   }
    public void sleep(int hours)
   {
        try
        {
                // 1000 milliseconds * 60 seconds * 60 minutes * hours
                Thread.sleep ( 1000 * 60 * 60 * hours);
        }
        catch (InterruptedException ie) { /* ignore */ } 
   }
    public abstract void makeNoise();
}
public Dog extends Animal
{
   public void makeNoise() { System.out.println ("Bark! Bark!"); }
}
 public Cow extends Animal
{
   public void makeNoise() { System.out.println ("Moo! Moo!"); }

CodeMonkeyCharlie provides a tutorial on Java abstract classes and methods:

This was last updated in July 2016

Next Steps

HashMap vs. Hashtable: Which map should you choose?

Continue Reading About Java abstract class

Dig Deeper on Software development best practices and processes

App Architecture
Software Quality
Cloud Computing
Security
SearchAWS
Close