When we should go for
interface, abstract class and concrete class?
1.If we don't know anything about implementation just we have
requirement specification then we should go for interface.
2.If we are talking about implementation but not completely (partial
implementation) then we should go for abstract class.
3.If we are talking about implementation completely and ready to
provide service then we should go for concrete class.
Interface
|
Abstract class
|
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.
|
Every
method present inside interface is always public and abstract whether we are
declaring or not.
|
Every method present inside abstract
class need not be public and abstract.
|
We
can't declare interface methods with the modifiers private, protected, final,
static, synchronized, native, strictfp.
|
There
are no restrictions on abstract class method modifiers.
|
Every
interface variable is always public static final whether we are declaring or
not.
|
Every abstract class variable need
not be public static final.
|
Every
interface variable is always public static final we can't declare with the
following modifiers. Private, protected, transient, volatile.
|
There
are no restrictions on abstract class variable modifiers.
|
For
the interface variables compulsory we should perform initialization at the
time of declaration otherwise we will get compile time error.
|
It is not require to perform
initialization for abstract class variables at the time of declaration.
|
Inside
interface we can't take static and instance blocks.
|
Inside
abstract class we can take both static and instance blocks.
|
Inside
interface we can't take constructor.
|
Inside abstract class we can take
constructor.
|