+ 2
Why we use interface in java?
3 Answers
+ 2
mostly because Java doesn't support multi inheritance tu avoid the the diamond of death caused by circular dependency if not checked but also because if you use inheritance you can set a contract for anyone intending to use your class should abide by, by setting behavior you expect to be overridden by anyone using your interface, it provides structure
+ 2
what is diamond of death?
+ 2
if class a depends on class b, class b depends on class c and class c depends on class a, this could lead the OS into a state of deadlock since we have circular dependency, in this situation the outcome is not known but to prevent against this multiple inheritance is not allowed in Java, not this is a common phenomena in C since this permitted.