Similarities b/w
Interface and Abstract class:
1. We can't create a object of both Interface and Abstract class.
2. We create object of the class who inherit either abstract class of interface.
3. abstract methods are contained in both interface and abstract classes.
Differences b/w Abstract class and interface:
1. We can't create a object of both Interface and Abstract class.
2. We create object of the class who inherit either abstract class of interface.
3. abstract methods are contained in both interface and abstract classes.
Differences b/w Abstract class and interface:
S.No
|
Interface
|
Abstract Class
|
1
|
If
we don't know anything about implementation just we have requirement
specification then we should go for interface.
|
If
we are talking about implementation but not completely (partial
implementation) then we should go for abstract class
|
2
|
Every method
is always public and abstract whether we are declaring or not. Hence
interface is 100% abstract class
|
Every
method present in Abstract class need not be public and abstract. And
Abstract class is having abstract methods as well as concrete methods also
|
3
|
Every
variable is always public,static and final whether we are declaring or not
|
There
is no restriction here
|
4
|
For
interface variables compulsory we should perform initialization at the time
of declaration otherwise we would get Compile time error
|
For
Abstract class variables its not required to perform initialization at the
time of declaration
|
5
|
It supports Multiple Inheritance
|
By extending abstract class you can not extend
another class because Java does not support multiple inheritance
|
6
|
we cannot create constructor
|
we can create constructor
|
7*
|
when you add a new method in existing interface it
breaks all its implementation and you need to provide an implementation in
all clients which is not good.
|
By using abstract class you can provide default
implementation in super class.
|
No comments:
Post a Comment