+ 4
What is difference between interface and abstract class in Java ?
2 ответов
+ 3
Class vs. interface
Some say you should define all classes in terms of interfaces, but I think recommendation seems a bit extreme. I use interfaces when I see that something in my design will change frequently.
interface vs. abstract class
Choosing interfaces and abstract classes is not an either/or proposition. If you need to change your design, make it an interface. However, you may have abstract classes that provide some default behavior. Abstract classes are excellent candidates inside of application frameworks.
+ 2
1. Intetface:- If we don't know anything about implementation just we have requirement specifications (100% Abstraction) then we should go for interface.
for ex. Servlet(I) plan for building
2. Abstract:- If we are taking about implementation but not completely (partial implementation) then we should go for Abstract class.
for ex. GenericServlet & HttpServlet partial complete building.
3. Concreate class:- If we are taking about implementation completely and ready to provide service then we should go for Concreate class.
for ex. MyOwnServlet fully complete building, ready to provide service.