1.
|
Class is a user defined data type which is used to define properties of data.
|
Interface is a type of class which is used for only declaration of methods and fields.
|
2.
|
Class can have zero, one or more abstract methods or can have final fields.
|
Interface have all abstract methods and final fields.
|
3.
|
All the program is written inside the class because of object oriented concept.
|
Interfaces are used for data hiding (abstraction).
|
4.
|
Class can extend to only one other class.
|
Interface can extend to multiple other interfaces but not with any class.
|
5.
|
Multiple classes can be combined together to form a single class.
|
Multiple interfaces can be combined together to form a single interface.
|
6.
|
Classes are allowed to extend with other classes, and subclasses inherit some or all the methods declared in the super classes are still classes.
|
Interfaces are allowed to extend with other interfaces, but subinterfaces cannot define the methods declared in the superinterfaces. superinterfaces are still interfaces not classes.
|
7.
|
A class can extend interfaces
|
Interface cannot extend classes
|
8.
|
Classes cannot be implemented
|
Interface must be implemented to other classes for writting their definition.
|
9.
|
Syntax
class ClassName
{
type Methodname()
{
//body of method
}
type fieldName ;
}
|
Syntax
interface InterfaceName
{
type methodName1();
type methodName2();
.
.
type field1 = value;
type field2 = value;
}
|
10.
|
Classes doesn't allow to declare methods. It possible by using abstract keyword.
|
Interface allows us to declare methods. Their body must be written into subclass.
|