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

"Interfaces are often used to describe the peripheral
abilities of a class, not its central identity, e.g. an
Automobile class might implement the Recyclable interface,
which could apply to many otherwise totally unrelated objects."
a cricketball class may implement the class bowlable which
could apply to many otherwise totally unrelated objects such
as BowlingBall or LawnBowlsBall or TenpinBowlingBall.

"An abstract class defines the core identity of its
descendants. If you defined a Dog abstract class then
Dalmation descendants are Dogs, they are not merely dogable.
Implemented interfaces enumerate the general things a class
can do, not the things a class is."
a Cricketball might extend/inherit the Ball abstract class
as above and in so doing recognise that a ball is an entity
with the common properties of diameter and volume not just
bowlable. here both abstract class and interface can be used
together.

One insightful difference and therefore an indicator of
usage is this. If an abstract class has all its methods
required to be overridden so that there is no common
behavior implemented in it (that its subclasses can use),
then you have effectively... Interface.
"If all the methods of an abstract class are uncompleted
then it is the same as an interface."..said this developer
or put another way , the more you implement methods in the
class for use by its descendants, the more you move away
from an interface and more towards an abstract class. So
interfaces are concerned with behaviors that are common in
concept but different in implementation and refer therefore
to exchanges between components at a system level. Typically
interfaces are used at the periphery of components so that
they can interface to other components that may be
implemented using possibly different languages for example.
Abstract classes however are concerned with behaviors that
are common in concept and in implementation.

Is This Answer Correct ?    30 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the statements?

1038


What are the approaches that you will follow for making a program very efficient?

1007


Write a program to find the greatest of three numbers in java?

938


what is mutual exclusion? How can you take care of mutual exclusion using java threads? : Java thread

1068


Why string is immutable with example?

905


Is singleton a bad practice?

984


What is hash in java?

897


When should I use a singleton?

977


What is array in java?

942


What is the difference between instanceof and isinstance?

985


How we can skip finally block of exception even if some exception occurs in the exception block in java?

877


Should a main method be compulsorily declared in all java classes?

995


Can subclass overriding method declare an exception if parent class method doesn't throw an exception?

998


What is var keyword ?

1124


What are aggregate functions explain with examples?

997