Is an interface a class?

Interface is just a contract which all implementing classes should follow. An interface is something like a template which cannot make an impact until a class implements it.


The concept of interfaces comes from Abstract Classes, where as abstract classes contains prototypes of method (or abstract methods) and can have few of its methods defined also, while interfaces contains only the prototypes(or signature) of method or abstract methods, whose definition is to be provided by the implementing class. so from the above statement it is clear that interfaces are like 100 percent abstract classes where - none of its method is defined. mentioning it again interfaces are like 100 percent abstract classes but not the classes.

"Interfaces are contracts for what a class can do"

A reason for introducing interface is, we can extend only single class but interface brought a new thing implement in java so we can implement thousands of interface.So we can not say that it is a class.

you can get more about this Here!


No, an interface is not a class in Java.

An interface is a type and all reference types (i.e. non-primitive types) handle quite similarly in Java. Often when people say "class" they are actually referring to a "reference type".

What might be confusing you is that an interface definition is stored in a .class file, but that's just a technical artifact of Java. In fact all reference type definitions (classes, interfaces, annotations, enums) are stored in .class files in Java.


An interface isn't a class, but you could say that both interfaces and classes are types.

From the Java specification:

In the Java programming language, every variable and every expression has a type that can be determined at compile-time. The type may be a primitive type or a reference type. Reference types include class types and interface types.

Notice though there is a special class called Class<T> that can represent both classes and interfaces:

Instances of the class Class represent classes and interfaces in a running Java application.

The fact that an interface is represented by a Class instance where isInterface is true could give you the impression that an interface is just a special type of class. However this is not the case.

Tags:

Java

Interface