Abstract methods means there is no default implementation for it and an implementing class will provide the details.

Essentially, you would have

abstract class AbstractObject {
   public abstract void method();
}

class ImplementingObject extends AbstractObject {
  public void method() {
    doSomething();
  }
}

So, it's exactly as the error states: your abstract method can not have a body.

There's a full tutorial on Oracle's site at: http://download.oracle.com/javase/tutorial/java/IandI/abstract.html

The reason you would do something like this is if multiple objects can share some behavior, but not all behavior.

A very simple example would be shapes:

You can have a generic graphic object, which knows how to reposition itself, but the implementing classes will actually draw themselves.

(This is taken from the site I linked above)

abstract class GraphicObject {
    int x, y;
    ...
    void moveTo(int newX, int newY) {
        ...
    }
    abstract void draw();
    abstract void resize();
}

class Circle extends GraphicObject {
    void draw() {
        ...
    }
    void resize() {
        ...
    }
}
class Rectangle extends GraphicObject {
    void draw() {
        ...
    }
    void resize() {
        ...
    }
}
Answer from Reverend Gonzo on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › abstract-methods-in-java-with-examples
Abstract Method in Java with Examples - GeeksforGeeks
July 12, 2025 - In Java, Sometimes we require just method declaration in super-classes. This can be achieved by specifying the Java abstract type modifier. Abstraction can be achieved using abstract class and abstract methods.
🌐
W3Schools
w3schools.com › java › java_abstract.asp
Java Abstraction
The abstract keyword is a non-access modifier, used for classes and methods: Abstract class: is a restricted class that cannot be used to create objects (to access it, it must be inherited from another class).
Discussions

Abstract methods in Java - Stack Overflow
Sometimes this idea comes from having a background in C++ and mistaking the virtual keyword in C++ as being "almost the same" as the abstract keyword in Java. In C++ virtual indicates that a method can be overridden and polymorphism will follow, but abstract in Java is not the same thing. More on stackoverflow.com
🌐 stackoverflow.com
implementing abstract methods/classes in java - Stack Overflow
Can I implement abstract methods in an abstract base class A in java? If the answer is yes and there is an implemented abstract method in a base class A and there is a derived class B from A (B is... More on stackoverflow.com
🌐 stackoverflow.com
java - What are abstract classes and abstract methods? - Stack Overflow
Possible Duplicate: Abstract class in Java 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 somet... More on stackoverflow.com
🌐 stackoverflow.com
Use of abstract methods and interfaces?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full - best also formatted as code block You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/learnjava
8
7
July 25, 2023
🌐
Oracle
docs.oracle.com › javase › tutorial › java › IandI › abstract.html
Abstract Methods and Classes (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)
Abstract classes cannot be instantiated, but they can be subclassed. An abstract method is a method that is declared without an implementation (without braces, and followed by a semicolon), like this:
🌐
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.
🌐
Programiz
programiz.com › java-programming › abstract-classes-methods
Java Abstract Class and Method (With Example)
Here, we have used the super() inside the constructor of Dog to access the constructor of the Animal. Note that the super should always be the first statement of the subclass constructor. Visit Java super keyword to learn more. The major use of abstract classes and methods is to achieve abstraction in Java.
Top answer
1 of 3
80

Abstract methods means there is no default implementation for it and an implementing class will provide the details.

Essentially, you would have

abstract class AbstractObject {
   public abstract void method();
}

class ImplementingObject extends AbstractObject {
  public void method() {
    doSomething();
  }
}

So, it's exactly as the error states: your abstract method can not have a body.

There's a full tutorial on Oracle's site at: http://download.oracle.com/javase/tutorial/java/IandI/abstract.html

The reason you would do something like this is if multiple objects can share some behavior, but not all behavior.

A very simple example would be shapes:

You can have a generic graphic object, which knows how to reposition itself, but the implementing classes will actually draw themselves.

(This is taken from the site I linked above)

abstract class GraphicObject {
    int x, y;
    ...
    void moveTo(int newX, int newY) {
        ...
    }
    abstract void draw();
    abstract void resize();
}

class Circle extends GraphicObject {
    void draw() {
        ...
    }
    void resize() {
        ...
    }
}
class Rectangle extends GraphicObject {
    void draw() {
        ...
    }
    void resize() {
        ...
    }
}
2 of 3
23

If you use the java keyword abstract you cannot provide an implementation.

Sometimes this idea comes from having a background in C++ and mistaking the virtual keyword in C++ as being "almost the same" as the abstract keyword in Java.

In C++ virtual indicates that a method can be overridden and polymorphism will follow, but abstract in Java is not the same thing. In Java abstract is more like a pure virtual method, or one where the implementation must be provided by a subclass. Since Java supports polymorphism without the need to declare it, all methods are virtual from a C++ point of view. So if you want to provide a method that might be overridden, just write it as a "normal" method.

Now to protect a method from being overridden, Java uses the keyword final in coordination with the method declaration to indicate that subclasses cannot override the method.

🌐
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. Java abstract classes may or may not contain abstract methods, i.e., methods without body ( public void get(); )
Find elsewhere
🌐
BeginnersBook -
beginnersbook.com › home › java › abstract method in java with examples
Abstract method in Java with examples
September 11, 2022 - A method must always be declared in an abstract class, or in other words you can say that if a class has an abstract method, it should be declared abstract as well. In the last tutorial we discussed Abstract class, if you have not yet checked it out read it here: Abstract class in Java, before reading this guide.
🌐
Quora
quora.com › How-do-I-write-an-example-program-for-an-abstract-method-in-Java
How to write an example program for an abstract method in Java - Quora
Answer (1 of 3): A simple way to demonstrate this is to have two classes, an abstract one and an ordinary one. The ordinary class then inherits from the abstract one. You could add a third class containing the main method, which instantiates the class. As an example you could have as an abstract...
🌐
Upgrad
upgrad.com › home › blog › software development › explore abstract method and class in java: learn rules to streamline your code
Master Abstract Method and Class in Java for Clear OOP
1 week ago - Below are the key facts that define an abstract class in Java: You cannot call new on an abstract class, so it serves as a blueprint rather than a directly usable type. An abstract class may contain both abstract methods (no body) and concrete methods (full implementation).
🌐
Medium
medium.com › @ashfaque-khokhar › abstract-classes-and-methods-738ef810e99d
Abstract Classes and Methods. In Java, abstract classes and methods… | by Ashfaque Khokhar | Medium
May 27, 2024 - In Java, abstract classes and methods are used to define common attributes and behaviors that can be shared by multiple subclasses while ensuring that certain methods are implemented in those subclasses.
🌐
Reddit
reddit.com › r/learnjava › use of abstract methods and interfaces?
r/learnjava on Reddit: Use of abstract methods and interfaces?
July 25, 2023 -

I understand the point of abstract classes even from a semantic perspective.

But I don't understand why would I need to use abstract methods? My issue is that they:

  1. Don't have a body so it's not like they're helping avoid copy-paste code.

  2. They *have* to be implemented by the first concrete class, and that feels like an obligation that takes away some sort of flexibility from the programmer.

Why not use empty methods in their place?

I have a similar gripe about interfaces.

How are they helping implement polymorphism if the methods don't have a body that I can reuse? If I have 2 classes with the same interface (say Pet interface, since I'm using Head First Java as a resource and that's the example they use) and that interface has a method actFriendly(). And now if both my concrete classes implement that same Pet interface in the exact same manner, I have to type the same code in both my classes, aka copy paste stuff and somehow that just feels like a big programming no-no.

Something about these two tools is just not clicking for me...I'd appreciate any help!

Thanks in advance!

Top answer
1 of 6
6
It’s the whole “they have to be implemented part”. I’ll talk more about interfaces since these days abstract classes with abstract methods aren’t super common. You can think of an interface as a contract, you’re guaranteeing that any concrete class that implements it will contain the methods specified by the interface (even if you don’t know exactly how they’re implemented). For example, you’ll know anything that implements List will contains methods like size(), add(E e) or get(int index). Why care? Well almost certainly the consumers of your concrete classes don’t care exactly how it’s methods are implemented, just that it has certain methods. Going back to the list example, your code probably doesn’t care if a List is really an ArrayList or a LinkedList or some custom list, all it cares about is that it’s some type of list, so using the List interface makes your code very adaptable to change. Similarly if you were writing code to interact with a database, you’d probably make some DatabaseHandler interface which defines certain operations and then could make concrete classes for a specific databases like MySqlHandler which implements those operations for a MySQL database. The consumers of your code shouldn’t care what database you’re using, just that you’re using a database with the operations you specified in the interface. So you’d use polymorphism my doing something like DatabaseHandler dbHandler = new MySqlHandler(), and your code would then have access to all the methods defined by DatabaseHandler, using the implementation from MySqlHandler. But what if in the future you want to use DynamoDB instead of MySQL? We’ll all you’d need to do is just create a DynamoDbHandler that implements DatabaseHandler and change the above line of code to DatabaseHandler dbHandler = new DynamoDbHandler(). Since both your DynamoDB and MySQL handlers implement the same interface, they’re guaranteed to always have the same collection of methods, even if the exact implementation of each differ, meaning from your consumer’s perspective it’s just a drop in replacement. If you weren’t using an interface, doing this type of change would typically consist of a lot more refactoring.
2 of 6
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full - best also formatted as code block You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
🌐
Quora
quora.com › What-are-abstract-methods-in-Java-1
What are abstract methods in Java? - Quora
Answer: Abstract methods are those types of methods that dont require implementation for its declaration. These methods don't have a body which means no implementation. A few properties of an abstract method are: An abstract method in Java is ...
Top answer
1 of 7
10

One of the most obvious uses of abstract methods is letting the abstract class call them from an implementation of other methods.

Here is an example:

class AbstractToy {
    protected abstract String getName();
    protected abstract String getSize();
    public String getDescription() {
        return "This is a really "+getSize()+" "+getName();
    }
}
class ToyBear extends AbstractToy {
    protected override String getName() { return "bear"; }
    protected override String getSize() { return "big"; }
}
class ToyPenguin extends AbstractToy {
    protected override String getName() { return "penguin"; }
    protected override String getSize() { return "tiny"; }
}

Note how AbstractToy's implementation of getDescription is able to call getName and getSize, even though the definitions are in the subclasses. This is an instance of a well-known design pattern called Template Method.

2 of 7
5

The abstract method definition in a base type is a contract that guarantees that every concrete implementation of that type will have an implementation of that method.

Without it, the compiler wouldn't allow you to call that method on a reference of the base-type, because it couldn't guarantee that such a method will always be there.

So if you have

MyBaseClass x = getAnInstance();
x.doTheThing();

and MyBaseClass doesn't have a doTheThing method, then the compiler will tell you that it can't let you do that. By adding an abstract doTheThing method you guarantee that every concrete implementation that getAnInstance() can return has an implementation, which is good enough for the compiler, so it'll let you call that method.

Basically a more fundamental truth, that needs to be groked first is this:

You will have instances where the type of the variable is more general than the type of the value it holds. In simple cases you can just make the variable be the specific type:

MyDerivedClassA a = new MyDerivcedClassA();

In that case you could obviously call any method of MyDerivedClassA and wouldn't need any abstract methods in the base class.

But sometimes you want to do a thing with any MyBaseClass instance and you don't know what specific type it is:

public void doTheThingsForAll(Collection<? extends MyBaseClass> baseClassReferences) {
  for (MyBaseClass myBaseReference : baseClassReferences) {
    myBaseReference.doTheThing();
  }
}

If your MyBaseClass didn't have the doTheThing abstract method, then the compiler wouldn't let you do that.

🌐
GeeksforGeeks
geeksforgeeks.org › java › abstract-classes-in-java
Abstract Class in Java - GeeksforGeeks
In Java, abstract class is declared with the abstract keyword. It may have both abstract and non-abstract methods(methods with bodies). An abstract is a Java modifier applicable for classes and methods in Java but not for Variables.
Published   July 23, 2025
🌐
Reddit
reddit.com › r/learnprogramming › [java] why would you use an abstract class as instead of an interface?
r/learnprogramming on Reddit: [Java] Why would you use an abstract class as instead of an interface?
February 3, 2014 -

The deal with abstract classes is that they are abstract, you can define abstract methods and also concrete methods. Them being classes means that when creating new classes you are limited to extending only one per class.

Interfaces on the other hand define abstract methods and also concrete methods through what I now learned is another use of the default keyword (the one I knew was switch cases). Interfaces can also be functional interfaces which means support for lambdas. You can implement more than one interface in a class.

Now that we know that both abstract classes and interfaces provide both support for concrete and abstract methods, and that you can "subclass" more interfaces in one class as opposed to "subclassing" abstract classes, as well as lambdas support for interfaces, why would there be a use for abstract classes? It seems interfaces can do all that abstract classes can do but better.

Top answer
1 of 5
38

Basically you want, if possible, to use interfaces wherever possible. The only difference between an interface and an abstract class, aside from classes only being able to extend one class, is that abstract classes can contain state. If you don't need to contain state it's better to use interfaces since a class can implement any number of interfaces.

So to answer your question:

It seems interfaces can do all that abstract classes can do but better.

No. Abstract classes can contain state, interfaces can't.

An example for using interfaces, abstract classes and concrete classes:

public interface UserDb {
    void storeUser(User user);
    default void storeUsers(User... users) {
        for(User u : users) {
            storeUser(u);
        }
    }
}

public abtract class AbstractUserDb implements UserDb {
    protected List<User> users = new ArrayList<>();

    @Override
    public void storeUser(User u) {
        users.add(u);
    }
}

public class JsonUserDb extends AbstractUserDb {
    @Override
    public void storeUser(User u) {
        super.storeUser(u);
        new ObjectMapper().writeValue(users, "users.json");
    }
}
2 of 5
14

Abstract classes can provide implementation of methods as well as just declarations, so they can provide common or base implementations for methods that may be used by many subclasses. Take a look at java.util.AbstractList, for example, which provides some base functionality to make it easier to implement the java.util.List interface. If you want to implement List, you don't have to actually implement all of the methods declared by that interface yourself—you can just extend AbstractList and implement the get() method, and the default implementations of all the other methods provided by AbstractList will work out of the box, using your get() method, to give you a minimal implementation of List.

Top answer
1 of 2
2

An abstract method is a method without a body. So you can't just call an abstract method of an abstract class (you cannot instantiate an abstract class directly). If you want to have your abstract game class with the abstract methods you need to have a class that extends this game class and specifically implements these methods without the abstract keyword.

Or you remove the abstract keyword from init and render and then the subclass of your Game class doesn't have to implement these methods but will take the one defined in your Game class.

Alternatively you can remove the abstract keyword from the methods in your game class but still @Override them in your subclass. That way you can define a default behavior for init and render and still change it in a subclass if needed.

public abstract class Game {

    public Game() {};

    public void init()
    {
        // do init stuff
    }

    public void render()
    {
        // do render stuff
    }
}




public class specificGame extends Game {

    public specificGame() {};

    // no need to implement init and render. But you can still override them

    @Override
    public void init()
    {
        // spefic init stuff
    }

    @Override
    public void render()
    {
        // specific render stuff
    }

}

More about abstract classes and methods https://docs.oracle.com/javase/tutorial/java/IandI/abstract.html

Is this what you want?

This is the main file:

package devex;

import devex.SubClass;

public class MainClass
{

    public static void main(String[] args)
    {
        SubClass.init();
        AClass.init();
    }
}

The this is the abstract class defining a default init

package devex;

public abstract class AClass
{

    public static void init() 
    {
        System.out.println("AClass init");
    }

}

This subclass extends AClass and overwrites init

package devex;

public class SubClass extends AClass
{

    public static void init()
    {
        System.out.println("Subclass init");
    }

}
2 of 2
0

The fact that your methods are abstract is secondary, here -- the main issue is that you're calling the methods as if they were declared static:

Game.init()
Game.render()

Instead, what you need in order to call these methods is an instance of the Game class and invoke those methods on that object:

Game game = new SubclassOfGame();
game.init()
game.render()
🌐
CodeGym
codegym.cc › java blog › java classes › java abstract class (abstraction in java)
Java Abstract Methods and Classes
April 24, 2025 - An abstract method is a method that has no implementation. That is, it just has a declaration, so you know the name, the return type, and the variables it will accept. Here is an example of a basic abstract method: public abstract int example(int ...