Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

when to use abstract class and when to use interface?

Answer Posted / rod

an excelent answer to this question is given by the
following link http://java.sys-con.com/node/36250

apart from the fact that it treats a motor and engine as
equivalent identical items when they are distinct, one
needing elec the other petrol or steam, but the analogy
still holds and is very well illustrated.

In short we use abstract classes to reduce complexity and
duplication, whilst we use interfaces to allow changes in
design without breaking the class hierarchy.

He uses an abstract motor class as a base class to both
solar powered and battery powered vehicles. But what happens
if you must then
describe a third class of vehicle which is a hybrid of these
2 types, you cannot inherit from them both to pick up the
methods of each class so you are stuck having to break the
class hierarchy and redesign.

However If you had used interfaces, you could implement both
the battery and solar car's ability to get the charge time
and minimum light to operate respectively from multiple
interfaces.

Is This Answer Correct ?    12 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is the use of bean managed and container managed with example?

1925


What is a native method in java programming?

1001


How do I get a substring?

927


What are the advantages of functions?

869


What is the difference between integer parseint and integer valueof?

963


What is a package in java? List down various advantages of packages.

1195


What 5 doubled?

930


Under what conditions is an object’s finalize() method invoked by the garbage collector?

977


What are decalarations?

1061


what is mena by object block any what is the use of that

2161


What is the purpose of javac exe?

1024


How do you use spaces in java?

944


What do you know about java?

898


What is toarray method in java?

1027


What is the order of arraylist in java?

1060