Tuesday 17 March 2015

Q 012) Abstract Class VS Interface




INTERFACE
ABSTRACT CLASS
01)
When :
When the implementation is unknown. And we only have SRS, Then Interface is a suitable choice.
When :
If we know the implementation partially then we should opt for abstract class.
02 )
Method:
Every method is always public and abstract weather we declare the keywords or not.
Method:
Every method need not be public. In addition to abstract methods we can declare concrete methods in Abstract Class as well.
03)
Method Modifiers :
Allowed: Static , final , native and strict fp.
Method Modifiers :
No restrictions on abstract class methods.





INTERFACE
ABSTRACT CLASS
04)
Variables:
Every variable in interface is public , static and final
 ( CONSTANTS )
Variables:
No restrictions.
05 )
Variable Modifiers :
Not Allowed : private,  protected, transient, volatile…
Variable Modifiers :
No restrictions.
06)
Variable Initialization :
Variable should be initialized at the time of declaration or will result in error.
Variable Initialization :
No restriction.




07)
Instance/ Static Block :
Using of Instance and static blocks will result in error.
Instance/ Static Block :
We can use both instance a static block.
08)
Constructors  :
Cannot use Constructors.
Constructors  :
We can declare Constructors which will be executed at the time of child class object creation.
09)
 Keyword :
Implements
Keyword :
 “ Extends



No comments:

Post a Comment