Is a Java interface an abstract class?

All interface are indeed abstract

Actually, you can declare an method as abstract within an interface... except any 'checkstyle' tool will tell you the abstract keyword is redundant. And all methods are public.

If a class implements an interface and does not implement all its methods, it must be marked as abstract. If a class is abstract, one of its subclasses is expected to implement its unimplemented methods.

To echo other answers, an interface is not a class.

An interface is a reference type, similar to a class, that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated—they can only be implemented by classes or extended by other interfaces.

Interfaces are not part of the class hierarchy, although they work in combination with classes.

When you define a new interface, you are defining a new reference data type. You can use interface names anywhere you can use any other data type name. If you define a reference variable whose type is an interface, any object you assign to it must be an instance of a class that implements the interface


To better explain why an interface is not a class, consider the following:

1/ an interface is a type used by values

2/ a class is for Objects

3/:

Object a = new Date();
String s = a.toString();
  • The type of the variable 'a' is Object (which is actually a type notation in Java source code meaning a reference to an Object),
  • but the class of the object it points to is Date.

The type (Object) only affects what code is valid according to the compiler's type-checking, but not what the code actually does.

The class of the object affects what the code does, so that the a.toString() call in the second line returns a String that looks like a Date, not one that looks like "java.lang.Object@XXXXXXXX".

Since an Interface is a type, it is used for values only, and will not represent what objects will actually do in term of runtime.


Thing is, while technically interfaces may be represented as classes in languages like Java, I wouldn't consider them classes.

Abstract? Hell yes. Class? No.

Interfaces cannot have constructors, neither properties, fields, function bodies, etc. Interfaces cannot be inherited, they are implemented (again, technically it might be true that implementing an interface is actually inheriting it in specific languages, but that's not my point.) Interfaces are more like 'contracts' as they do not define any behaviour whatsoever like classes.

Now if this is a homework then you shouldn't really argue about these sort of stuff with the teacher. Just check your lecture notes and see if the word "class" is mentioned anywhere in the your teacher's definition of interface.