Abstract class v/s Interface in Java 8
- At a very high level, it looks very similar but actually they are different in many ways.
- Also, considering the fact that default method in interface helps us to achieve loose coupling and backward compatibility
| No. | Abstract Classes | Interface |
| 1 | Contains members variables | All variables are actually constants |
| 2 | It can have constructors | Interface cannot have constructors |
| 3 | Can hold state of an object using instance member variables | Since, all variables are static and final therefore no concept of holding state of an object |
| 4 | Forces to implement abstract methods or else declare class as abstract | default methods can be overridden, if required but never forces |
No comments:
Post a Comment