when to use abstract class and when to use interface?
Answer Posted / amit
Abstract provides both methods with and without body.
Adding new methods in abstract class in middle of
development life cycle won't break existing sub classes
unless these methods are declared as mustoverride. If there
are frequent addition of new methods properties and so on.
one should use abstract..
Whereas on the other hand interface can fill gap of
multiple inheritance. One can
implement from more than one interface. Not same with
Abstract. One can inherit
from only one abstract class.
| Is This Answer Correct ? | 44 Yes | 6 No |
Post New Answer View All Answers
Can a top level class be private or protected?
How to change the priority of thread or how to set priority of thread?
What is the functionality of the stub?
Can a static class implement an interface?
What happens if an exception is throws from an object's destructor?
What is an array in java?
Explain exception chaining in java?
Is null a string in java?
What are the two environment variables that must be set in order to run any java programs?
What is meant by data hiding/encapsulation?
Can an interface be defined inside a class?
What is charat java?
Given a singly linked list, how will you print out its contents in the reverse order? Can you do it with consuming any extra space?
What is the use of put method?
What is the purpose of default constructor?