what is difference between abstract and interface?
can i give real time example for the two topics?
Answer Posted / lakshmi
Interface has no implementation, but they have to be
implemented.
Abstract class’s methods can have implementations and they
have to be extended.
Interfaces can only have method declaration (implicitly
public and abstract) and fields (implicitly public static)
Abstract class’s methods can’t have implementation only
when declared abstract.
Interface can inherit more than one interfaces
Abstract class can implement more than one interfaces, but
can inherit only one class
Abstract class must override all abstract method and may
override virtual methods
Interface can be used when the implementation is changing
Abstract class can be used to provide some default behavior
for a base class.
Interface makes implementation interchangeable
Interface increase security by hiding the implementation
Abstract class can be used when implementing framework
Abstract classes are an excellent way to create planned
inheritance hierarchies and also to use as non-leaf classes
in class hierarchies.
| Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
Can we declare a constructor as final?
Difference between notify() method and notifyall() method in java?
What is the purpose of static methods and static variables?
Can vector have duplicates in java?
Which class cannot be a subclass in java?
Can a method be overloaded based on different return type but same argument type?
What is an empty list in java?
Tell us something about different types of casting?
What is the use of set in java?
What is ascii format?
Why is the singleton pattern considered to be an anti pattern?
Explain notify() method of object class ?
Is hashset sorted in java?
What is the collections api in java programming?
Why hashmap is used in java?