Friday, 20 November 2020

Abstract class v/s Interface in Java 8

 

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
1Contains members variablesAll variables are actually constants
2It can have constructorsInterface cannot have constructors
3Can hold state of an object using instance member variablesSince, all variables are static and final therefore no concept of holding state of an object
4Forces to implement abstract methods or else declare class as abstractdefault methods can be overridden, if required but never forces

No comments:

Post a Comment