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


Please Help Members By Posting Answers For Below Questions

How does hashset work in java?

569


Is hashset sorted in java?

667


What is purpose of applet programming?

641


What is illegal identifier in java?

538


What is java Applet?

652






What is immutability in java?

610


How do you override a method?

551


What is void class in java?

528


Why we go for collections in java?

556


Explain why wait(), notify() and notifyall() methods are in object class rather than in the reading class?

563


Why are parameters used in functions?

534


What is unicode used for?

575


Do I need java on my computer?

528


What is indexof?

549


hi am an engineering student and my next plan is for ms in either in us or australia i got my passport but i dont know anything bout visa can u give brief idea 1)How to get prepared for visa and 2)How to apply for top universities and 3)How to pay the fee and so on These all are basic questions plz give me a clear idea

1465