What is the difference between Abstract Class and Interface
Answer Posted / vikrant
Nothing stops you using interfaces and abstract classes
interchangeably. The difference is in the ideology where to
use it.
An abstract class is to be used when one needs to create a
hierarchy. e.g. Poodle, Pointer and Chihuahua are all breeds
breeds of dogs, they have some common characteristics as
dogs and some special characteristics of its breed. so all
breeds (Poodle, Pointer and Chihuahua classes) will inherit
from the Dog class.
Interface on the other hand is just a contract. The
implementing classes need not be related. Say a 3-D figure.
Sphere, Cone, Cylinder are all 3-D shapes they have nothing
in common apart from being 3-D figures. Each will have their
own equation for calculating area, perimeter, volume. All
need to specify in Shapes interface is that the implementing
class must be able to calculate area, perimeter, volume.
| Is This Answer Correct ? | 4 Yes | 0 No |
Post New Answer View All Answers
How many types of methods are there?
Are constructors methods?
How many bytes is a unicode character?
Are functions objects in java?
What are mutable classes?
When wait(), notify(), notifyall() methods are called does it releases the lock or holds the acquired lock?
If you are given the name of the function at run time how will you invoke the function?
Explain the difference between intermediate and terminal operations in java8?
Where import statement is used in a java program?
How do you call a reference in java?
Why java applets are more useful for intranets as compared to internet?
What is the difference between equals() and == in java?
What does exclamation mean in java?
Is class forname reflection?
When can you say a graph to be a tree?