Difference between interface and abstract class
- In the interface, if we don't know about implementation and just we have requirement specification then we should go for an interface. But In the abstract class, If we are talking about partial implementation but not complete then we should go for abstract class.
- In the interface, every method is always public and abstract whether we are declaring or not. But In the abstract class, every method need not be public and abstract. we can take concrete method also.
- In the interface, every method is always public and abstract, hence we can't declare with the following modifiers private, protected, static, synchronized, native, strictfp. But In the abstract class, there is no restriction on abstract class methods.
- In the interface, every variable is always public, static and final whether we are declaring or not. But In the abstract class, every variable need not be public, static and final.
- In the interface, every variable is always public, static and final. hence, we can't declare with the following modifiers private, protected, transient and volatile. But In the abstract class, there is no restriction on the abstract class variable.
- In the interface, for every variable, we should perform initialization at the time of declaration only otherwise we will get Compile Time Error. But For abstract class variables, we are not required to perform initialization at the time of declaration.
- Inside interface, we can't declare static and instance blocks.But in the abstract class, we can declare static and instance blocks.
- Inside interface, we can't declare the constructor. But in abstract class, we can declare constructor
No comments:
Post a Comment
Be the first to comment!
Don't just read and walk away, Your Feedback Is Always Appreciated. I will try to reply to your queries as soon as time allows.
Note:
1. If your question is unrelated to this article, please use our Facebook Page.
2. Please always make use of your name in the comment box instead of anonymous so that i can respond to you through your name and don't make use of Names such as "Admin" or "ADMIN" if you want your Comment to be published.
Regards,
JavaByChetan
Back To Home