top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is main difference between class & interface in Java?

+1 vote
What is main difference between class & interface in Java?
posted Sep 4, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Class can Be Instantiated where interface can not be instantiated

Each Object in class will have its own state where as in interface each objected created after implementing will have the same state

Every Object of class will have the same behavior unless overridden where as every Object will have a define its own behavior by implementing the contract defined.

A Class can inherit only one Class and can implement many interfaces where as an Interface cannot inherit any classes while it can implement many interfaces

All the variables are instance by default in class unless otherwise specified where as all the variables are static final by default, and a value needs to be assigned at the time of definition

All the methods in a class should be having a definition unless decorated with an abstract keyword where as in interface all the methods are abstract by default and they will not have a definition.

answer Sep 5, 2014 by Salil Agrawal