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
What value is a variable of the string type automatically initialized?
What type of value does sizeof return?
Can we have two methods in a class with the same name?
What methodology can be employed to locate substrings inside a string?
Can we override constructors?
Does list allow duplicates in java?
What are the two main uses of volatile in Java?
What is array initialization in java?
What is the access scope of a protected method?
What do you mean by static variable?
What is the map interface in java programming?
What are selection structures?
Why is String immutable?
Can we create object of inner class in java?
What does %d do in java?