Difference between Class, Interface

  • by

As a software engineer, we know very well how and where to use class and interface. In java, before writing any java program will create a Class and then add some methods to it. An Interface denotes a group of logical entities and also acts as a contract between two sub systems, while communicating with each other. See the bellow difference between class and interface to know the exact idea of concept.

Class -:
1] Class has both definition and an implementation
2] A Java abstract class can have instance methods that implement default behavior.
3] An abstract class may contain non-final variables.
4] A Java abstract class can have the usual flavours of class members like private, protected, etc.
5] A Java abstract class should be extended using keyword “extends”.
6] an abstract class can extend another Java class and implement multiple Java interfaces.
7] All the methods should be having a definition unless decorated with an abstract keyword
8] A Class can inherit only one Class and can implement many interfaces
9] Every Object will have the same behavior unless overridden.
10] Each Object created will have its own state

1] Interface only has a definition
2] Methods of a Java interface are implicitly abstract and cannot have implementations
3] Variables declared in a Java interface is by default final
4] Members of a Java interface are public by default.
5] Java interface should be implemented using keyword “implements”
6] An interface can extend another Java interface only
7] All the methods are abstract by default and they will not have a definition.
8] An Interface cannot inherit any classes while it can extend many interfaces
9] Every Object will have to define its own behavior by implementing the contract defined.
10] Each objected created after implementing will have the same state

Leave a Reply