Difference Between Interface and Abstract Class:
Interface
|
Abstract Class
|
1.
If we don’t know anything about implementation
just we have requirement specification, then we can use Interface
|
If we know partial Implementation(not full) then we can
use Abstract Class.
|
2.
Every Method in interface is public abstract, that
why interface is Pure abstract class (100%).
|
In addition to the abstract method Abstract class can also
have Non abstract Method(concrete method).
|
3.
Methods in interface are public and abstract
modifiers we can’t use private,protected,final,static,synchronized,native and
strictfp modifiers.
|
There is no restriction for Methods modifiers in Abstract class.
|
4.
By Implicitly, variable in interface will be
public static final.
|
In abstract class the variable can be of any data types.
|
5.
Since variables in interface is public static
final we can’t use as private or protected ,transient or volatile modifiers.
|
There is no restriction for Variable in Abstract class
|
6.
We should assign the value to variable at the
time of declaration otherwise compiler will give error. public static final int
x=3;
|
There is no such restriction in Abstract class.
|
7.
We can’t declare any instance or static method
inside the interface.
|
Can have instance or static method inside the abstract
class.
|
8.
We can’t have constructor inside the
interface, since the variable is static
|
We can have constructor inside the Abstract class.
|
9.
Interface can extend more than one interface,
Interface C extends A,B
|
Abstract class can extend class or Abstract class
|
10.
Interface Car{
public static final int x=10;
public int speed();
}
|
abstract class Engine{ public abstract void engineType(String carType);
public String
engineColor(){ return "red"; }
|
No comments:
Post a Comment