1) In interface we can only have declaration of methods but in abstract class, method implementation can be there.
2) In interface we can only have final static variables.
3) Can implement more than one intefaces, so multiple inheritance is only possible with help of interfaces in java.
4) Interface can have only public method, where as abstract class can have public, protected and private members also.
5) We use abstract class when we want to provide some default implementation to the implementing class and use interface when we want all the methods to be implemented by the subclasses.
One very common question on this point is that why at all do we need interfaces, when same thing can be acheived by abstract classes by declaring all methods as abstract.
Interface force non abstract implementing class to implement all beheviour where as abstract class cannot.
Recommended reading Book By kathy siera for SCJP.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment