An abstract class starts to make more sense when you deal with a large codebase and you are working with other devs (at least it did for me). You create one to establish a common pattern for other classes to extend and to avoid duplication of code. An abstract class cannot be instantiated but it CAN store state and concrete methods. Answer from Successful_Leg_707 on reddit.com
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_abstract.asp
Java Abstraction
The body is provided by the subclass (inherited from). An abstract class can have both abstract and regular methods:
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ abstract-classes-in-java
Abstract Class in Java - GeeksforGeeks
Java abstract class is a class that can not be instantiated by itself, it needs to be subclassed by another class to use its properties.
Published ย  July 23, 2025
Discussions

What is the point of an abstract class?
An abstract class starts to make more sense when you deal with a large codebase and you are working with other devs (at least it did for me). You create one to establish a common pattern for other classes to extend and to avoid duplication of code. An abstract class cannot be instantiated but it CAN store state and concrete methods. More on reddit.com
๐ŸŒ r/learnprogramming
27
15
August 24, 2021
oop - Abstract class in Java - Stack Overflow
Important Note:- Abstract classes cannot be used to instantiate objects, they can be used to create object references, because Java's approach to run-time Polymorphism is implemented through the use of superclass references. Thus, it must be possible to create a reference to an abstract class ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
oop - What are some practical examples of abstract classes in java? - Stack Overflow
When and why should abstract classes be used? I would like to see some practical examples of their uses. Also, what is the difference between abstract classes and interfaces? More on stackoverflow.com
๐ŸŒ stackoverflow.com
java - What are abstract classes and abstract methods? - Software Engineering Stack Exchange
I got several explanations but so far I'm not able to understand that what are the abstract classes and methods in Java. Some said it has to do something with the security of the program, other sai... More on softwareengineering.stackexchange.com
๐ŸŒ softwareengineering.stackexchange.com
December 11, 2012
๐ŸŒ
Oracle
docs.oracle.com โ€บ javase โ€บ tutorial โ€บ java โ€บ IandI โ€บ abstract.html
Abstract Methods and Classes (The Javaโ„ข Tutorials > Learning the Java Language > Interfaces and Inheritance)
You cannot instantiate them, and they may contain a mix of methods declared with or without an implementation. However, with abstract classes, you can declare fields that are not static and final, and define public, protected, and private concrete methods. With interfaces, all fields are automatically public, static, and final, and all methods that you declare or define (as default methods) are public.
๐ŸŒ
YouTube
youtube.com โ€บ watch
Abstract Classes and Methods in Java Explained in 7 Minutes
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
Top answer
1 of 15
355

An abstract class is a class which cannot be instantiated. An abstract class is used by creating an inheriting subclass that can be instantiated. An abstract class does a few things for the inheriting subclass:

  1. Define methods which can be used by the inheriting subclass.
  2. Define abstract methods which the inheriting subclass must implement.
  3. Provide a common interface which allows the subclass to be interchanged with all other subclasses.

Here's an example:

abstract public class AbstractClass
{
    abstract public void abstractMethod();
    public void implementedMethod() { System.out.print("implementedMethod()"); }
    final public void finalMethod() { System.out.print("finalMethod()"); }
}

Notice that "abstractMethod()" doesn't have any method body. Because of this, you can't do the following:

public class ImplementingClass extends AbstractClass
{
    // ERROR!
}

There's no method that implements abstractMethod()! So there's no way for the JVM to know what it's supposed to do when it gets something like new ImplementingClass().abstractMethod().

Here's a correct ImplementingClass.

public class ImplementingClass extends AbstractClass
{
    public void abstractMethod() { System.out.print("abstractMethod()"); }
}

Notice that you don't have to define implementedMethod() or finalMethod(). They were already defined by AbstractClass.

Here's another correct ImplementingClass.

public class ImplementingClass extends AbstractClass
{
    public void abstractMethod() { System.out.print("abstractMethod()"); }
    public void implementedMethod() { System.out.print("Overridden!"); }
}

In this case, you have overridden implementedMethod().

However, because of the final keyword, the following is not possible.

public class ImplementingClass extends AbstractClass
{
    public void abstractMethod() { System.out.print("abstractMethod()"); }
    public void implementedMethod() { System.out.print("Overridden!"); }
    public void finalMethod() { System.out.print("ERROR!"); }
}

You can't do this because the implementation of finalMethod() in AbstractClass is marked as the final implementation of finalMethod(): no other implementations will be allowed, ever.

Now you can also implement an abstract class twice:

public class ImplementingClass extends AbstractClass
{
    public void abstractMethod() { System.out.print("abstractMethod()"); }
    public void implementedMethod() { System.out.print("Overridden!"); }
}

// In a separate file.
public class SecondImplementingClass extends AbstractClass
{
    public void abstractMethod() { System.out.print("second abstractMethod()"); }
}

Now somewhere you could write another method.

public tryItOut()
{
    ImplementingClass a = new ImplementingClass();
    AbstractClass b = new ImplementingClass();

    a.abstractMethod();    // prints "abstractMethod()"
    a.implementedMethod(); // prints "Overridden!"     <-- same
    a.finalMethod();       // prints "finalMethod()"

    b.abstractMethod();    // prints "abstractMethod()"
    b.implementedMethod(); // prints "Overridden!"     <-- same
    b.finalMethod();       // prints "finalMethod()"

    SecondImplementingClass c = new SecondImplementingClass();
    AbstractClass d = new SecondImplementingClass();

    c.abstractMethod();    // prints "second abstractMethod()"
    c.implementedMethod(); // prints "implementedMethod()"
    c.finalMethod();       // prints "finalMethod()"

    d.abstractMethod();    // prints "second abstractMethod()"
    d.implementedMethod(); // prints "implementedMethod()"
    d.finalMethod();       // prints "finalMethod()"
}

Notice that even though we declared b an AbstractClass type, it displays "Overriden!". This is because the object we instantiated was actually an ImplementingClass, whose implementedMethod() is of course overridden. (You may have seen this referred to as polymorphism.)

If we wish to access a member specific to a particular subclass, we must cast down to that subclass first:

// Say ImplementingClass also contains uniqueMethod()
// To access it, we use a cast to tell the runtime which type the object is
AbstractClass b = new ImplementingClass();
((ImplementingClass)b).uniqueMethod();

Lastly, you cannot do the following:

public class ImplementingClass extends AbstractClass, SomeOtherAbstractClass
{
    ... // implementation
}

Only one class can be extended at a time. If you need to extend multiple classes, they have to be interfaces. You can do this:

public class ImplementingClass extends AbstractClass implements InterfaceA, InterfaceB
{
    ... // implementation
}

Here's an example interface:

interface InterfaceA
{
    void interfaceMethod();
}

This is basically the same as:

abstract public class InterfaceA
{
    abstract public void interfaceMethod();
}

The only difference is that the second way doesn't let the compiler know that it's actually an interface. This can be useful if you want people to only implement your interface and no others. However, as a general beginner rule of thumb, if your abstract class only has abstract methods, you should probably make it an interface.

The following is illegal:

interface InterfaceB
{
    void interfaceMethod() { System.out.print("ERROR!"); }
}

You cannot implement methods in an interface. This means that if you implement two different interfaces, the different methods in those interfaces can't collide. Since all the methods in an interface are abstract, you have to implement the method, and since your method is the only implementation in the inheritance tree, the compiler knows that it has to use your method.

2 of 15
79

A Java class becomes abstract under the following conditions:

1. At least one of the methods is marked as abstract:

public abstract void myMethod()

In that case the compiler forces you to mark the whole class as abstract.

2. The class is marked as abstract:

abstract class MyClass

As already said: If you have an abstract method the compiler forces you to mark the whole class as abstract. But even if you don't have any abstract method you can still mark the class as abstract.

Common use:

A common use of abstract classes is to provide an outline of a class similar like an interface does. But unlike an interface it can already provide functionality, i.e. some parts of the class are implemented and some parts are just outlined with a method declaration. ("abstract")

An abstract class cannot be instantiated, but you can create a concrete class based on an abstract class, which then can be instantiated. To do so you have to inherit from the abstract class and override the abstract methods, i.e. implement them.

๐ŸŒ
DataCamp
datacamp.com โ€บ doc โ€บ java โ€บ abstract
abstract Keyword in Java: Usage & Examples
The abstract keyword in Java is used to declare a class or a method that cannot be instantiated directly or must be implemented by subclasses, respectively.
Find elsewhere
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ abstract-class-in-java
Abstract Class in Java | DigitalOcean
August 3, 2022 - Abstract class in Java is similar to interface except that it can contain default method implementation. An abstract class can have an abstract method without body and it can have methods with implementation also. abstract keyword is used to create a abstract class and method.
๐ŸŒ
I'd Rather Be Writing
idratherbewriting.com โ€บ java-abstract-methods
Java: Abstract classes and abstract methods | I'd Rather Be Writing Blog and API doc course
January 2, 2015 - Java lets developers declare that a class should never have an instance by using the abstract keyword. In Java, abstract means that the class can still be extended by other classes but that it can never be instantiated (turned into an object).
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ java โ€บ java_abstraction.htm
Java - Abstraction
A Java class which contains the abstract keyword in its declaration is known as abstract class.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ core java โ€บ abstract classes in java
Abstract Classes in Java | Baeldung
January 8, 2024 - Letโ€™s keep in mind that all these scenarios are good examples of full, inheritance-based adherence to the Open/Closed principle. Moreover, since the use of abstract classes implicitly deals with base types and subtypes, weโ€™re also taking advantage of Polymorphism. Note that code reuse is a very compelling reason to use abstract classes, as long as the โ€œis-aโ€ relationship within the class hierarchy is preserved. And Java 8 adds another wrinkle with default methods, which can sometimes take the place of needing to create an abstract class altogether.
๐ŸŒ
Quora
quora.com โ€บ How-do-I-run-an-abstract-class-in-Java
How to run an abstract class in Java - Quora
Answer (1 of 2): TL;DR: You can't. Longer version: Abstract classes and interfaces enable the developer to define how a type of class, that is concrete classes that implement the interface or are subclasses of the abstract class, can be interacted with, and, in the case of abstract classes, all...
๐ŸŒ
Programiz
programiz.com โ€บ java-programming โ€บ abstract-classes-methods
Java Abstract Class and Method (With Example)
Become a certified Java programmer. Try Programiz PRO! ... The abstract class in Java cannot be instantiated (we cannot create objects of abstract classes). We use the abstract keyword to declare an abstract class.
๐ŸŒ
BeginnersBook
beginnersbook.com โ€บ 2013 โ€บ 05 โ€บ java-abstract-class-method
Abstract Class in Java with example
It can have abstract methods(methods without body) as well as concrete methods (regular methods with body). A normal class(non-abstract class) cannot have abstract methods. In this guide we will learn what is a abstract class, why we use it and what are the rules that we must remember while working with it in Java.
๐ŸŒ
Jenkov
jenkov.com โ€บ tutorials โ€บ java โ€บ abstract-classes.html
Java Abstract Classes
March 9, 2015 - A Java abstract class is a class which cannot be instantiated, meaning you cannot create new instances of an abstract class. The purpose of an abstract class is to function as a base for subclasses.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ abstraction-in-java-2
Abstraction in Java - GeeksforGeeks
Abstraction in Java is the process of hiding internal implementation details and showing only essential functionality to the user. It focuses on what an object does rather than how it does it.
Published ย  October 22, 2025
Top answer
1 of 6
16

First of all, the examples will be in C#. But I think you'll have no problem understanding it. So...

You CANNOT instantiate objects of an abstract class. You must have a subclass that derives from the class, if you want to instantiate it. But this probably won't help you since you may have come across that before.

So let's try an example.

Suppose you want to lose weight and your nutritionist asks you to track your food intake. When you go to her again, you can't tell her that you ate a "food". Although it's not wrong, since all food has calories, it is too "abstract" for her. So you need to tell her WHICH food.

So, if she were to code that... She'd have an abstract class Food.

abstract class Food
{
    public int CaloriesPerPound { get; set; }
    //...
}

Why? Because that wouldn't allow you to say "I ate a food".

{
    Food fries = new Food(); //This won't even compile
}

So you need concrete classes:

class Fruit : Food
{
 //Other stuff related only to fruits
}

class Bread : Food
{ 
 //Other stuff related only to Bread
}

So you'll have to tell exactly which food it is.

{
   Apple desert = new Apple(); //Now we are talking
}

But she still needs the food class, it is still interesting to her:

class Meal
{
    public List<Food> Foods { get; set; }
    //Other meal related stuff
    public int TotalCalories()
    {
        int calories = 0;
        foreach (Food food in Foods)
        {
            calories = calories + food.CaloriesPerPound * FoodQuantity;
        }
        return calories;
    }
}

That's an example of when you need an abstract class. When you want to have a base class, but you don't want anyone creating an object of your class.

An abstract CAN have abstract methods. It doesn't need to. Is totally ok to have an abstract class without abstract methods. Speaking of which...

Abstract method is something that it's too broad. There's no similarities on how things work, so the classes that derive from your class that has an abstract method won't be able to call the super class implementation. And you're also forcing all the sub classes to implement their version of that method.

Let's try another example? An Animal Band Simulator. You'd have animals, and each one of them would make a sound. But those are very different "implementations", they have nothing in common A dog differs from a cat, a cat from an elephant, an elephant from a cricket. So you'd have an abstract method MakeSound.

class Animal
{
    public abstract void MakeSound();
}

But, if you have an abstract method in your class, that makes the whole class abstract!

abstract class Animal
{
    public abstract void MakeSound();
}

So the rest of the code might be:

class Dog : Animal
{
    public void MakeSound()
    {
        //bark at the moon
    }
}

class Cat : Animal
{
    public void MakeSound()
    {
        //meowing for food
    }
}

And the BAND!

class AnimalBand
{
    public List<Animal> Animals { get; set; }
    public void RockOn()
    {
        foreach (Animal animal in Animals)
        {
            animal.MakeSound();
        }
    }
}

So this is an example of when you use an abstract method.

I guess this is the essence. It may be a little forced/convoluted, but I think it gets the point across. Go back to the examples that didn't help you before and see if they make sense now.

I'm go out on a limb and say you're a beginner. This stuff may seem strange to you, and you may not see any benefit in using abstract classes.

It's ok. It's strange for almost all of us when we start. But in time, you'll learn to appreciate it.

2 of 6
5

An abstract class is a class that cannot be instantiated (i.e. new myAbstractClass()). It is used as a template for other classes to inherit.

An abstract method is a method in an abstract class that can be overridden (i.e. implemented) in a derived class.

The difference between an interface and an abstract class is that you can put functionality in an abstract class (i.e. ordinary or virtual methods) that can be utilized in the derived class, whereas an interface is just an empty template.

๐ŸŒ
TheServerSide
theserverside.com โ€บ definition โ€บ abstract-class
What is an Abstract Class? | Definition from TechTarget
For example, using the keyword implements will make a Java interface, while the keyword extends makes an abstract class.
๐ŸŒ
Whitman College
whitman.edu โ€บ mathematics โ€บ java_tutorial โ€บ java โ€บ javaOO โ€บ abstract.html
Writing Abstract Classes and Methods
Instead, the Number class makes sense only as a superclass to classes like Integer and Float which implement specific kinds of numbers. Classes such as Number, which implement abstract concepts and should not be instantiated, are called abstract classes.