Definition

Java abstract class

Contributor(s): Matthew Haughn

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

Continue Reading About Java abstract class

Dig Deeper on Mobile development and deployment

PRO+

Content

Find more PRO+ content and other member only offers, here.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

File Extensions and File Formats

Powered by:

SearchCloudApplications

SearchSoftwareQuality

SearchFinancialApplications

SearchSAP

SearchManufacturingERP

DevOpsAgenda

Close