top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is main difference between class & interface in Java?

+1 vote
323 views
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

Instantiation
Class can Be Instantiated where interface can not be instantiated

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

Behavior
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.

Inheritance
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

Variables
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

Methods
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
...