The general age-old principle is: Stick with interfaces until you're forced to write an abstract class.

An interface in Java is a non-instantiable type which defines a public interface that other types can choose to conform to.

  • Interfaces can declare public methods, which must be defined by their implementors. All such methods are implicitly abstract, so you don't need to use the word abstract.
  • In old versions of Java, interfaces could not have default implementations, so every method was abstract. This is no longer the case, and interfaces can now have default implementations that get used in implementing classes unless replaced.
  • In recent versions of Java, interfaces can declare private helper methods. These can help in implementing default implementations.
  • Interfaces can never have constructors or instance variables.
  • A class can implement several interfaces.

An abstract class is just a class that cannot be instantiated. Abstract classes are not required to define any abstract methods, though you'll usually want to.

  • Abstract classes can declare methods with any visibility: public, private, protected, and package-private.
  • Abstract classes can implement methods or leave them abstract. Methods in an abstract class are not implicitly abstract and must be marked as such.
  • An abstract class can have constructors, which must be called by extending classes in their own constructor using super. An abstract class can have instance variables of any visibility, and these work just like instance variables in any parent class.
  • A class can only extend one class, either an abstract one or a concrete one. A class' abstractness does not change the number of superclasses it's allowed to have.

abstract classes should be the exception and not the norm. You should use an abstract class if you need to maintain some internal state while also letting subclasses define your own behavior. A great example of this comes from the Java Swing GUI library: AbstractButton. AbstractButton is the abstract parent of things that behave vaguely like buttons in a window, including buttons, toggle buttons, and items in a menu. Anyone can subclass AbstractButton and implement its members to define a button-like display. But AbstractButton also has to maintain a lot of internal state (much of it coming from JComponent) in order to communicate with the window and with the Swing API as a whole.

If you want to define the public interface for a collection of types, use an interface. If you want to provide default implementations for some of those methods and are using a version of Java released after 2014, use interfaces. If you need default implementations but are stuck in the 2000s, use an abstract class. Regardless of Java version, if you need private state such as instance variables or custom initialization like a constructor, use an abstract class.

Answer from Silvio Mayolo on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › difference-between-abstract-class-and-interface-in-java
Difference Between Abstract Class and Interface in Java - GeeksforGeeks
Abstract class can have constructors and variables, whereas interface contains only constants and no constructors. ... An abstract class is a class that cannot be instantiated and is used as a base for other classes.
Published: May 16, 2026
🌐
Unstop
unstop.com › home › blog › 10+ key differences between abstract class & interface in java
10+ Key Differences Between Abstract Class & Interface In Java
January 8, 2025 - Similarities Between Java Vs. C++ ... An abstract class is a class with abstract and concrete methods used for shared behavior. An interface is a blueprint with abstract methods, allowing multiple inheritance and defining a contract for classes.
Discussions

java - When to use abstraction and when an interface? - Stack Overflow
I vaguely understand the difference between abstraction and interfaces, but what I can't understand at all, is when to use abstraction and when an interface. What are the variables needed for me to More on stackoverflow.com
🌐 stackoverflow.com
What is the difference between an Interface and an Abstract class?

In terms of code, they're very similar, which often raises confusion like yours.

Conceptually, I think of it this way. When you inherit from an abstract class, you're saying that you are a type of the class. You have the same attributes.

When you implement an interface, you're saying that you do the things that that interface does.

In one sentence, abstract classes allow you to inherit state/variables/data, interfaces allow you inherit behaviors.

More on reddit.com
🌐 r/java
27
13
October 16, 2014
oop - What is the difference between an interface and abstract class? - Stack Overflow
In Java, this rule is strongly enforced, while in PHP, interfaces are abstract classes with no method declared. In Python, abstract classes are more a programming trick you can get from the ABC module and is actually using metaclasses, and therefore classes. And interfaces are more related to duck typing in this language and it's a mix between ... More on stackoverflow.com
🌐 stackoverflow.com
Abstraction vs abstract class/interfaces - Java - Code with Mosh Forum
In this java tutorial under the abstraction we are taught to hide the implementation details and make our code less coupled. But on this video we are not taught about abstract classes. Isn’t abstract classes not related to the abstraction? why they are in a separate video. More on forum.codewithmosh.com
🌐 forum.codewithmosh.com
0
May 6, 2023
🌐
BYJUS
byjus.com › gate › difference-between-abstract-class-and-interface-in-java
Difference between Abstract Class and Interface in Java
February 16, 2024 - An abstract class contains an abstract keyword on the declaration whereas an Interface is a sketch that is used to implement a class. Explore more differences between abstract class and interface in java.
Top answer
1 of 2
2

The general age-old principle is: Stick with interfaces until you're forced to write an abstract class.

An interface in Java is a non-instantiable type which defines a public interface that other types can choose to conform to.

  • Interfaces can declare public methods, which must be defined by their implementors. All such methods are implicitly abstract, so you don't need to use the word abstract.
  • In old versions of Java, interfaces could not have default implementations, so every method was abstract. This is no longer the case, and interfaces can now have default implementations that get used in implementing classes unless replaced.
  • In recent versions of Java, interfaces can declare private helper methods. These can help in implementing default implementations.
  • Interfaces can never have constructors or instance variables.
  • A class can implement several interfaces.

An abstract class is just a class that cannot be instantiated. Abstract classes are not required to define any abstract methods, though you'll usually want to.

  • Abstract classes can declare methods with any visibility: public, private, protected, and package-private.
  • Abstract classes can implement methods or leave them abstract. Methods in an abstract class are not implicitly abstract and must be marked as such.
  • An abstract class can have constructors, which must be called by extending classes in their own constructor using super. An abstract class can have instance variables of any visibility, and these work just like instance variables in any parent class.
  • A class can only extend one class, either an abstract one or a concrete one. A class' abstractness does not change the number of superclasses it's allowed to have.

abstract classes should be the exception and not the norm. You should use an abstract class if you need to maintain some internal state while also letting subclasses define your own behavior. A great example of this comes from the Java Swing GUI library: AbstractButton. AbstractButton is the abstract parent of things that behave vaguely like buttons in a window, including buttons, toggle buttons, and items in a menu. Anyone can subclass AbstractButton and implement its members to define a button-like display. But AbstractButton also has to maintain a lot of internal state (much of it coming from JComponent) in order to communicate with the window and with the Swing API as a whole.

If you want to define the public interface for a collection of types, use an interface. If you want to provide default implementations for some of those methods and are using a version of Java released after 2014, use interfaces. If you need default implementations but are stuck in the 2000s, use an abstract class. Regardless of Java version, if you need private state such as instance variables or custom initialization like a constructor, use an abstract class.

2 of 2
0

Interfaces:

Say you have an interface, like:

interface Animal {
  String makeNoise();
}

and a couple of classes that implement Animal:

class Cat implements Animal {
    String makeNoise() {
        return "Meow";
    }
}

class Dog implements Animal {
    String makeNoise() {
        return "Woof";
    }
}

Now you can use the interface as the return type, so a method can return a Cat or a Dog.

String makeAnimalMakeNoise(int animalId) {
    Animal animal = pretendAnimalService.getDogOrCat(animalId);

    animal.makeNoise();
}

Abstract Classes:

Let's say you have an abstract class:

abstract class Animal {
    public String makeNoise() {
        return "Whistle";
    }

    abstract public String getName();
}

Now, any class that extends this would need to implement the getName method:

class Cat extends Animal {
    String getName() {
        return "Pussy";
    }
}

class Dog extends Animal {
    String getName() {
        return "Fido";
    }
}

Both of the above classes implemented the required getName method, but they also have access to the parent classes makeNoise method, which can also be overridden if required.

It's important to note the other differences too, which are:

  • You can only extend one abstract class but you may implement multiple interfaces.
  • Interfaces should be used when different types should have the same method signature whereas abstract classes should be used when implementations share a common behaviour.
  • They are not mutually exclusive.
  • An interface can only have public methods where as abstract classes can have public and protected methods.
🌐
Medium
medium.com › @saygiligozde › what-are-the-differences-between-abstract-class-and-interface-in-java-a41674127a47
What are the differences between abstract class and interface in Java? | by Gozde Saygili Yalcin | Medium
September 14, 2022 - An interface, similar to a class, is a reference type that can only contain nested types, constants, method signatures, default methods, and static methods. Only ‘default methods’ and ‘static methods’ have a method body.
🌐
Tpoint Tech
tpointtech.com › difference-between-abstract-class-and-interface
Difference between Abstract Class and Interface in Java - Tpoint Tech
August 29, 2026 - In Java, both abstract classes and interfaces help in achieving abstraction, but they are used in different ways. Abstract classes are for sharing common functionality among related classes, while interfaces define a set of methods that any class can implement. In this chapter, we will learn ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › difference-between-abstract-class-and-interface-in-java
Abstract Class vs Interface in Java: Key Differences | DigitalOcean
August 3, 2022 - Understand differences between abstract classes and interfaces in Java. Learn when to use each with examples, multiple inheritance, and design best practices.
Find elsewhere
🌐
Coderanch
coderanch.com › t › 775191 › java › Abstract-Interface-difference
Abstract and Interface difference (Beginning Java forum at Coderanch)
July 5, 2023 - The abstract methods have to be overwritten and given a body with code between its squiggle brackets. interface These can not be instantiated either. None of the methods can have a body. one or more interfaces can be implemented in a different class Each method has to be overwritten or the compiler will complain.
🌐
Scaler
scaler.com › home › topics › java › difference between abstract class and interface in java
Difference between Abstract Class and Interface in Java - Scaler Topics
February 21, 2024 - The main difference between Abstract Class and Interface in Java is that an abstract class can have both abstract and concrete methods, while an interface can only have abstract methods.
Top answer
1 of 16
2508

Interfaces

An interface is a contract: The person writing the interface says, "hey, I accept things looking that way", and the person using the interface says "OK, the class I write looks that way".

An interface is an empty shell. There are only the signatures of the methods, which implies that the methods do not have a body. The interface can't do anything. It's just a pattern.

For example (pseudo code):

// I say all motor vehicles should look like this:
interface MotorVehicle
{
    void run();

    int getFuel();
}

// My team mate complies and writes vehicle looking that way
class Car implements MotorVehicle
{

    int fuel;

    void run()
    {
        print("Wrroooooooom");
    }


    int getFuel()
    {
        return this.fuel;
    }
}

Implementing an interface consumes very little CPU, because it's not a class, just a bunch of names, and therefore there isn't any expensive look-up to do. It's great when it matters, such as in embedded devices.


Abstract classes

Abstract classes, unlike interfaces, are classes. They are more expensive to use, because there is a look-up to do when you inherit from them.

Abstract classes look a lot like interfaces, but they have something more: You can define a behavior for them. It's more about a person saying, "these classes should look like that, and they have that in common, so fill in the blanks!".

For example:

// I say all motor vehicles should look like this:
abstract class MotorVehicle
{

    int fuel;

    // They ALL have fuel, so lets implement this for everybody.
    int getFuel()
    {
         return this.fuel;
    }

    // That can be very different, force them to provide their
    // own implementation.
    abstract void run();
}

// My teammate complies and writes vehicle looking that way
class Car extends MotorVehicle
{
    void run()
    {
        print("Wrroooooooom");
    }
}

Implementation

While abstract classes and interfaces are supposed to be different concepts, the implementations make that statement sometimes untrue. Sometimes, they are not even what you think they are.

In Java, this rule is strongly enforced, while in PHP, interfaces are abstract classes with no method declared.

In Python, abstract classes are more a programming trick you can get from the ABC module and is actually using metaclasses, and therefore classes. And interfaces are more related to duck typing in this language and it's a mix between conventions and special methods that call descriptors (the __method__ methods).

As usual with programming, there is theory, practice, and practice in another language

2 of 16
995

The key technical differences between an abstract class and an interface are:

  • Abstract classes can have constants, members, method stubs (methods without a body) and defined methods, whereas interfaces can only have constants and methods stubs.

  • Methods and members of an abstract class can be defined with any visibility, whereas all methods of an interface must be defined as public (they are defined public by default).

  • When inheriting an abstract class, a concrete child class must define the abstract methods, whereas an abstract class can extend another abstract class and abstract methods from the parent class don't have to be defined.

  • Similarly, an interface extending another interface is not responsible for implementing methods from the parent interface. This is because interfaces cannot define any implementation.

  • A child class can only extend a single class (abstract or concrete), whereas an interface can extend or a class can implement multiple other interfaces.

  • A child class can define abstract methods with the same or less restrictive visibility, whereas a class implementing an interface must define the methods with the exact same visibility (public).

🌐
Baeldung
baeldung.com › home › java › core java › using an interface vs. abstract class in java
Using an Interface vs. Abstract Class in Java | Baeldung
March 4, 2026 - In addition to these, Java 8 new features support static and default methods in interfaces to support backward compatibility. Methods in an interface are implicitly abstract if they are not static or default and all are public.
🌐
Code with Mosh
forum.codewithmosh.com › java
Abstraction vs abstract class/interfaces - Java - Code with Mosh Forum
May 6, 2023 - Interfaces are by nature abstract and their methods are abstract unless you explicitly make them otherwise, and they are used to contain/list “ideas” (in the form of methods) that need to be implemented by other classes.
🌐
javaspring
javaspring.net › blog › difference-between-abstract-and-interface-in-java
Understanding the Difference Between Abstract Classes and Interfaces in Java — javaspring.net
Abstract classes are suitable for defining a common structure for a group of related classes that share state or code, while interfaces are ideal for defining capabilities and contracts that unrelated classes can implement — including several ...
🌐
Reddit
reddit.com › r/csharp › whats the difference between interface and abstract class? are they not use the same way?
r/csharp on Reddit: Whats the difference between Interface and Abstract class? Are they not use the same way?
October 29, 2020 - If a class that implements an interface does not define all the methods of the interface, then it must be declared abstract and the method definitions should be provided by the subclass that extends the abstract class.
Top answer
1 of 16
580

I will give you an example first:

public interface LoginAuth{
   public String encryptPassword(String pass);
   public void checkDBforUser();
}

Suppose you have 3 databases in your application. Then each and every implementation for that database needs to define the above 2 methods:

public class DBMySQL implements LoginAuth{
          // Needs to implement both methods
}
public class DBOracle implements LoginAuth{
          // Needs to implement both methods
}
public class DBAbc implements LoginAuth{
          // Needs to implement both methods
}

But what if encryptPassword() is not database dependent, and it's the same for each class? Then the above would not be a good approach.

Instead, consider this approach:

public abstract class LoginAuth{
   public String encryptPassword(String pass){
            // Implement the same default behavior here 
            // that is shared by all subclasses.
   }

   // Each subclass needs to provide their own implementation of this only:
   public abstract void checkDBforUser();
}

Now in each child class, we only need to implement one method - the method that is database dependent.

2 of 16
228

Nothing is perfect in this world. They may have been expecting more of a practical approach.

But after your explanation you could add these lines with a slightly different approach.

  1. Interfaces are rules (rules because you must give an implementation to them that you can't ignore or avoid, so that they are imposed like rules) which works as a common understanding document among various teams in software development.

  2. Interfaces give the idea what is to be done but not how it will be done. So implementation completely depends on developer by following the given rules (means given signature of methods).

  3. Abstract classes may contain abstract declarations, concrete implementations, or both.

  4. Abstract declarations are like rules to be followed and concrete implementations are like guidelines (you can use it as it is or you can ignore it by overriding and giving your own implementation to it).

  5. Moreover which methods with same signature may change the behaviour in different context are provided as interface declarations as rules to implement accordingly in different contexts.

Edit: Java 8 facilitates to define default and static methods in interface.

public interface SomeInterfaceOne {

    void usualAbstractMethod(String inputString);

    default void defaultMethod(String inputString){
        System.out.println("Inside SomeInterfaceOne defaultMethod::"+inputString);
    }
}

Now when a class will implement SomeInterface, it is not mandatory to provide implementation for default methods of interface.

If we have another interface with following methods:

public interface SomeInterfaceTwo {

    void usualAbstractMethod(String inputString);

    default void defaultMethod(String inputString){
        System.out.println("Inside SomeInterfaceTwo defaultMethod::"+inputString);
    }

}

Java doesn’t allow extending multiple classes because it results in the “Diamond Problem” where compiler is not able to decide which superclass method to use. With the default methods, the diamond problem will arise for interfaces too. Because if a class is implementing both

SomeInterfaceOne and SomeInterfaceTwo

and doesn’t implement the common default method, compiler can’t decide which one to chose. To avoid this problem, in java 8 it is mandatory to implement common default methods of different interfaces. If any class is implementing both the above interfaces, it has to provide implementation for defaultMethod() method otherwise compiler will throw compile time error.

🌐
Simplilearn
simplilearn.com › home › resources › software development › abstract class vs interface java: understanding abstraction in java
Abstract Class vs Interface Java: A Complete Guide | Simplilearn
February 18, 2026 - How do you define the abstract class & interface in Java? Being the main building blocks of Java, learn the major abstract class vs interface java differences.
Address: 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Great Learning
mygreatlearning.com › blog › it/software development › abstract class vs interface in java
Difference Between Abstract Class and Interface in Java
January 16, 2025 - Read this blog to understand Interface in Java in more detail. ... In object-oriented programming (OOP), both abstract classes and interfaces are used to define abstract types, but they serve different purposes.
🌐
DEV Community
dev.to › manikandan_a8f99e0153ef77 › differences-between-abstract-class-and-interface-in-java-29gh
Differences between abstract class and interface in Java - DEV Community
October 22, 2025 - 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.
🌐
Medium
medium.com › @nakulmitra2114 › abstract-classes-vs-interfaces-in-java-3213b10c70e1
Abstract Classes vs Interfaces in Java | by Nakul Mitra | Medium
September 17, 2024 - In Java, abstract classes and interfaces are two fundamental concepts used to implement abstraction and achieve polymorphism. They play a critical role in defining the structure and behavior of Java applications. Understanding the differences between them and knowing when to use each is key to mastering Object-Oriented Programming (OOP) in Java.