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.

Answer from Vimal Bera on Stack Overflow
🌐
Medium
harsh05.medium.com › abstract-classes-vs-interfaces-in-java-when-and-how-to-use-them-5ca5d5c825b5
Abstract Classes vs Interfaces in Java: When and How to Use Them | by @Harsh | Medium
October 10, 2024 - Along the way, I also explored how multiple inheritance, although not directly supported in Java, can be achieved using interfaces. ... An abstract class in Java is a class that cannot be instantiated on its own. Instead, it serves as a blueprint for other classes that extend it.
🌐
Baeldung
baeldung.com › home › java › core java › using an interface vs. abstract class in java
Using an Interface vs. Abstract Class in Java | Baeldung
June 24, 2025 - They both might contain a set of methods declared and defined with or without their implementation. i.e., static & default methods(defined) in an interface, instance methods(defined) in abstract class, abstract methods(declared) in both of them · Let’s look at some scenarios when one should go with an interface: If the problem needs to be solved using multiple inheritances and is composed of different class hierarchies · When unrelated classes implement our interface. For example, Comparable provides the compareTo() method that can be overridden to compare two objects
🌐
GeeksforGeeks
geeksforgeeks.org › java › difference-between-abstract-class-and-interface-in-java
Difference Between Abstract Class and Interface in Java - GeeksforGeeks
Method Implementation: All methods in an interface are by default abstract and must be implemented by any class that implements the interface.From Java 8, interfaces can have default and static methods with concrete implementations.From Java 9, interfaces can also have private methods. Variables: Variables declared in an interface are by default public, static, and final (constants). Example: This example demonstrates interface implementation.
Published   July 23, 2025
Top answer
1 of 16
581

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.

🌐
InfoWorld
infoworld.com › home › blogs › java challengers
When to use abstract classes vs. interfaces in Java | InfoWorld
December 6, 2023 - From an object-oriented programming perspective, the main difference between an interface and an abstract class is that an interface cannot have state, whereas the abstract class can have state with instance variables.
🌐
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 expect that classes that extend your abstract class have many common methods or fields, or require access modifiers other than public (such as protected and private). You want to declare non-static or non-final fields. This enables you to define methods that can access and modify the state of the object to which they belong. Consider using interfaces if any of these statements apply to your situation: You expect that unrelated classes would implement your interface. For example, the interfaces Comparable and Cloneable are implemented by many unrelated classes.
🌐
DigitalOcean
digitalocean.com › community › tutorials › difference-between-abstract-class-and-interface-in-java
Difference between Abstract Class and Interface in Java | DigitalOcean
August 4, 2022 - We can use abstract keyword to make a class abstract but interfaces are a completely different type and can have only public static final constants and method declarations. Abstract classes methods can have access modifiers as public, private, protected, static but interface methods are implicitly public and abstract, we can’t use any other access modifiers with interface methods.
Top answer
1 of 16
968

How about an analogy: when I was in the Air Force, I went to pilot training and became a USAF (US Air Force) pilot. At that point I wasn't qualified to fly anything, and had to attend aircraft type training. Once I qualified, I was a pilot (Abstract class) and a C-141 pilot (concrete class). At one of my assignments, I was given an additional duty: Safety Officer. Now I was still a pilot and a C-141 pilot, but I also performed Safety Officer duties (I implemented ISafetyOfficer, so to speak). A pilot wasn't required to be a safety officer, other people could have done it as well.

All USAF pilots have to follow certain Air Force-wide regulations, and all C-141 (or F-16, or T-38) pilots 'are' USAF pilots. Anyone can be a safety officer. So, to summarize:

  • Pilot: abstract class
  • C-141 Pilot: concrete class
  • ISafety Officer: interface

added note: this was meant to be an analogy to help explain the concept, not a coding recommendation. See the various comments below, the discussion is interesting.

2 of 16
822

While your question indicates it's for "general OO", it really seems to be focusing on .NET use of these terms.

In .NET (similar for Java):

  • interfaces can have no state or implementation
  • a class that implements an interface must provide an implementation of all the methods of that interface
  • abstract classes may contain state (data members) and/or implementation (methods)
  • abstract classes can be inherited without implementing the abstract methods (though such a derived class is abstract itself)
  • interfaces may be multiple-inherited, abstract classes may not (this is probably the key concrete reason for interfaces to exist separately from abtract classes - they permit an implementation of multiple inheritance that removes many of the problems of general MI).

As general OO terms, the differences are not necessarily well-defined. For example, there are C++ programmers who may hold similar rigid definitions (interfaces are a strict subset of abstract classes that cannot contain implementation), while some may say that an abstract class with some default implementations is still an interface or that a non-abstract class can still define an interface.

Indeed, there is a C++ idiom called the Non-Virtual Interface (NVI) where the public methods are non-virtual methods that 'thunk' to private virtual methods:

  • http://www.gotw.ca/publications/mill18.htm
  • http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Non-Virtual_Interface
Find elsewhere
🌐
Medium
medium.com › @nwonahr › interfaces-vs-abstract-classes-in-c-whats-the-difference-and-when-to-use-them-9af5ab21b1f9
Interfaces vs Abstract Classes in C#: What’s the Difference and When to Use Them | by Richard Nwonah | Medium
September 22, 2024 - Since C# doesn’t support multiple ... system. Example: A Printer class could implement both IDevice and IPrintable interfaces to follow the contract for being both a device and having printable properties....
🌐
Javatpoint
javatpoint.com › difference-between-abstract-class-and-interface
Abstract vs Interface - javatpoint
Difference between Abstract class and Interface or difference between interface and abstract class in java or abstract class vs interface in abstraction with example of abstract class and example of interface,abstract class vs interface in java, example of abstract class and interface in java
🌐
Ash Allen Design
ashallendesign.co.uk › blog › interfaces-vs-abstract-classes-in-php
Interfaces vs Abstract Classes in PHP | Ash Allen Design
January 2, 2024 - For example, let's create a MyHouse class that extends our House abstract class: ... You might have noticed that in the House class that we have declared an abstract public method called openDoor(). This is basically allowing us to define a method's signature that a child class should include in a similar way as we would with an interface.
🌐
Guru99
guru99.com › home › java tutorials › difference between abstract class and interface in java
Difference Between Abstract Class and Interface in Java
November 25, 2024 - Interfaces never contain instance ... ... An abstract class permits you to make functionality that subclasses can implement or override whereas an interface only permits you to state functionality but not to implement it...
🌐
QuickStart
quickstart.com › blog › software-engineering › when-and-how-to-use-abstract-class-and-interface
Abstract Classes vs. Interfaces: Decoding the OOP Dilemma in Software Engineering | QuickStart
September 24, 2024 - The abstract class acts as the interface for plugins, ensuring that they adhere to a specific contract. Database Models: In object-relational mapping (ORM) frameworks, abstract classes can represent database tables or entities.
🌐
Codefinity
codefinity.com › blog › Interface-vs-Abstract-Class
Interface vs Abstract Class
Understand the differences between interfaces and abstract classes in object-oriented programming (OOP). Interfaces define methods a class must implement, promoting modularity and flexibility. Abstract classes offer a mix of implemented and abstract methods, providing a foundation for subclasses.
🌐
LearnYard
read.learnyard.com › low-level-design › class-vs-abstract-class-vs-interface
Class vs Abstract Class vs Interface vs Object
April 10, 2025 - Use an abstract class when you want to define a common structure and behavior for related classes, enforcing certain functionalities through abstract methods. Use an interface when you want to specify a contract (what functionalities a class must provide) for achieving a specific behavior, allowing for different implementations in different classes.
Top answer
1 of 5
2

Note: please forgive the C# syntax, but the principle of the answer is the same for Java and C#.

Now when i started programming I noticed that in all subclasses i basically needed to do the exact same thing

Based on this, it seems like you think abstract classes are only allowed to declare abstract methods. This is not the case.

An abstract class is a class that cannot be instantiated directly (only its derivations can be instantiated). An abstract method is a method in an abstract class which must be implemented in the derived class.

But an abstract class can have non-abstract methods:

public abstract class Artikel
{
    public int ArtikelId { get; set; }

    public string SayHello()
    {
        return "Hi, I'm artikel " + ArtikelId;
    }
}

When you derive Artikel into subclasses, you do not need to repeat the method body of the SayHello method. Its body has been declared in the base class and can be used by all of the derived classes.

I thought of making Artikel not abstract and put an interface between Artikel and the other classes

Interfaces prevent the ability to create a common method body. If you were to use an interface:

public interface IArtikel
{
    string SayHello();
}

Then you will be required to implement this method separately in every class:

public class Book : IArtikel
{
    public string SayHello()
    {
        // custom book logic
    }
}

// And the same for all other derived classes.

It's also possible to make an seperate class which inherits from Artikel where I can put all the methods, but then there the methods would still be needed to made three times, one for each subclass right?

Don't take this the wrong way, but your attempts at solving this suggest you don't really master OOP. If this SeparateClass was created as another (4th) subclass from Artikel, how would you expect e.g. the Book class to rely on the methods found in SeparateClass?

Is it a bad design choice if I keep Artikel as abstract?

Keep Artikel abstract, but give it non-abstract methods (i.e. with method bodies) for each method that you are now copy/pasting between all of its subclasses.

2 of 5
1

You can have a base class as an abstract class which implements the Artikel interface. In the abstract class you can define the common implementation. Then you can derive LP, Book and Boardgame from that super class. In my opinion it is better to have a abstract class rather than copying the same code in all 3 sub classes.

🌐
ProjectManagement.com
projectmanagement.com › blog-post › 69110 › interface-vs--abstract-class
ProjectManagement.com - Interface Vs. Abstract Class
Serializable is another example, making it possible to use the built-in mechanism in Java for serializing an object that implements it. This is virtually always done using an Interface, because you might need to make a class capable of participating in more than one of these built-in services. So my answer is this: if your purpose is to create polymorphism, use an Abstract Class.
Top answer
1 of 3
4

I like to think of interfaces as contracts (this object will have property X & Y and method Z) but makes no assumptions about implementation (at least they did before Default Interface Implementations as of C# 8: https://devblogs.microsoft.com/dotnet/default-implementations-in-interfaces, although I use these sparingly if ever).

Abstract classes (and derived non-sealed classes) can be thought of as just a place to share implementation that's common between supersets of classes and their subsets. Abstract classes provide an object-oriented way of supporting the Don't Repeat Yourself (DRY) principle (https://www.c-sharpcorner.com/article/software-design-principles-dry-kiss-yagni) where the implementation you would otherwise repeat doesn't make sense outside of the context of your class hierarchy.

Interfaces & abstract classes are by no means mutually exclusive and can be used in conjunction with each other depending on the context.

2 of 3
1

abstract classes are to define a common base class for inheritance, without implementing any actual methods.

because c# does not support multiple inheritance, interfaces are the solution. a class can inherit from one base class, but it can implement many interfaces. interfaces can only be implemented. an interface can not inherit from another interface.

due to issues with inheritance chains, inheritance is often considered an anti-pattern, interface design is recommend instead. with interface design you define contacts that define properties and methods. then classes must implement. other languages use protocols/traits which are slight more feature rich than interfaces.

one past advantage with classes, was you could define default behavior, and interfaces were abstract (no implementations). But modern C# allows default implemations for interfaces.

so my recommendation is to avoid class inheritance (and never more than 1 deep, that is only inherit from base), but rather use interfaces and extension methods to extend classes.