I was thinking about that, and I had some doubts.

When I declare an interface, for example:

public interface MyInterface
   public void method1();
   public void method2();

Could these interface methods be considered abstract? What I mean is that the concept of an abstract method is:

An abstract method is a method that is declared, but contains no implementation.

So, could these methods be considered abstract? They are not "pure" abstract methods as I'm not using the abstract word, but conceptually, it looks like they are.

What can you tell me about it?


  • Probably best on SO – billy.bob Sep 30 '11 at 11:33
  • 5
    @billy.bob - I think it's too abstract for Stack Overflow. There's not a specific coding issue here. – ChrisF Sep 30 '11 at 12:09
  • Is this Java code? – Andres F. Jun 18 '13 at 21:56
  • no it's not. it's just an example. the question is not focused on any programming languages. – rogcg Jun 19 '13 at 12:34

An interface is like a "purely" abstract class. The class and all of its methods are abstract. An abstract class can have implemented methods but the class itself cannot be instantiated (useful for inheritance and following DRY).

For an interface, since there isn't any implementation at all they are useful for their purpose: a contract. If you implement the Interface then you must  implement the methods in the interface.

So the difference is an abstract class can have implemented methods whereas a interface cannot.

The reason they are separate is so a class can implement several interfaces. Java and C# restrict a class to inherent from a single parent class. Some languages allow you to inherit from multiple classes and you could accomplish the work of an interface via a "purely" abstract class. But multiple inheritance has its problems, namely the dreaded Diamond Problem

  • +1 for incorporating the difference between inheritance of an abstract class and implementation of one or more interfaces. – user37772 Sep 30 '11 at 15:55
  • Diamond Problem is an awesome paradox. – rogcg Sep 30 '11 at 16:43
  • 1
    I dissagree with 'An interface is like a "purely' abstract class" part. They are 2 different types of OO 'building blocks', so they are really not similar at all. They share some common features, but in nature they are different types, more like men and women for example :) – NoChance Oct 2 '11 at 22:27
  • 5
    @Emmand Kareem I do not dissagree with 'An interface is like a "purely" abstract class' part. That's why i wrote it :-). If you have any good reasons for your disagreement please post, id like to hear – coder Oct 3 '11 at 12:59
  • It's worth noting that c#8 also introduces the concept of a default interface implementation – John Wu Jan 8 at 20:07

I found an usefull answer here: http://download.oracle.com/javase/tutorial/java/IandI/abstract.html

All of the methods in an interface are implicitly abstract, so the abstract modifier is not used with interface methods (it could be—it's just not necessary).

  • 1
    Also note that an abstract class extends one other object. Interfaces have no notion of a superclass. – user1249 Sep 30 '11 at 11:39
  • 2
    Also note that you can implement multiple interfaces, but you can only inherit from one class, abstract or not. – NullUserException Sep 30 '11 at 14:12
  • @ThorbjørnRavnAndersen: An interface can extend one or more interfaces. It isn't the same things as a super class, but it is a level of inheritance. – unholysampler Sep 30 '11 at 14:41
  • You can implement multiple interfaces. Looks like the concept of multiple inheritance, but not exactly. – rogcg Sep 30 '11 at 16:38
  • @unholysampler, which is not a superclass - as I said. – user1249 Oct 1 '11 at 0:06

Abstract classes can have abstract methods.

Interfaces can only have abstract methods.

method1() and method2() in your example are abstract methods.


The difference here is that abstract classes can contain implementation details, although cannot be instantiated by themselves. Whereas an interface is merely a template for a class

  • 8
    Abstract methods cannot contain implementation details. Abstract classes can. – Matt H Sep 30 '11 at 11:46
  • I know the difference between a method and a class - but I can't understand the point you're making? – billy.bob Sep 30 '11 at 12:04
  • Your answer states that abstract methods can contain implementation details - they can't. Just a typo? – Matt H Sep 30 '11 at 12:07
  • 1
    I fixed the typo. – Martijn Verburg Sep 30 '11 at 13:35
  • 1
    @billy.bob this question is about the abstact method though. – SoylentGray Oct 3 '11 at 15:52

So in a subclass, inherited abstract method can again go abstract without implementation , while if a class implements an interface it's method must be implemented.


Interface classes don't have abstract methods. They don't have any methods at all. They just have a list of methods that another class would have to implement to be able to conform to the interface. In your example, there is no method method1 and no method method2 until someone adds these methods to a class.

Not the answer you're looking for? Browse other questions tagged or ask your own question.