can u give one sinario when you use Abstract Class and When
you use Interface.

Answer Posted / srinivasa

If we have more than two classes with same method names but
their implementation is different.we can go for interface.
Example: JDBC API Interfaces. Every data base vender
implements these interfaces with thier implementation code.

If we want to use some common method implementaions for
multiple classes along with their own implementation we can
go for abstract class.

Example:Servlet API:
HttpServlet is an abstract class in which init() is
implemented used by every servlet that extends.Every
servlet implement their own service method.

Is This Answer Correct ?    10 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is purpose of applet programming?

903


I want to persist data of objects for later use. What’s the best approach to do so?

707


Is ++ operator is thread safe in java?

701


Why constructor has no return type?

839


What are some examples of variable costs?

717


What are the differences between abstract class and interface?

749


What does || mean in code?

793


Explain listiterator and methods in listiterator?

758


What is meant by design patterns?

796


What is diamond operator in java?

717


What one should take care of, while serializing the object?

673


what is synchronization? : Java thread

784


Is char a method in java?

755


What is a Null object?

1203


What is oop in java?

720