Thursday, March 30, 2017

Difference between interface and Abstract class in java


Difference between interface and Abstract class in java




                                           Interface
Abstract class
a)      If we don’t know anything about implementation and just we have requirements speciation then we should go for interface.
A )If we are taking about implementation but not completely   (partial implementation) then we should go for abstract class.
b)     Inside interface every method is always public and abstract weather we are declaring or not hence interface is considered as 100 % pure abstraction.
B)Every method present inside abstract class need not be public and abstract and we can take concrete method also
c)                 As every interface method is always public and abstract and hence we can’t declare with the following modifiers
private,protected,final,static,synchronized,naticeand strictfp
C) These are no restrictions on abstract class method modifiers.
d)     Every variable present inside interface is always public static final weather we are declaring or not
D ) every variable present inside abstract class need not be public static final
e)      As every interface is always public static final we can’t declare with the following modifiers private, protected ,volatile & transient modifiers
E ) these are no restrictions on abstract class variable modifiers
f)       For interface variables compulsory we should perform initialization at her time of declaration only otherwise we will get compile time error
F ) For abstract class variable we are not required to perform initialization at the time of declaration.
g)      Inside interface we cannot declare static and instance  blocks
G )inside abstract class we can declare static & instance blocks

h)     Inside interface we cannot declare constructors
H )Inside abstract class we can declare  constructor


No comments:

Post a Comment