We use Abstract class and interface to enforce some rules to the classes which extends/implements. For example we can define a class say "Bird" and we can declare methods say "Fly()", "Walk()". This means whatever the class that is derived from Bird has to override or give definition for Fly() and Walk() and therefore we are making sure that all the derived classes follows or has the common functionalities. In other way the classes derived from superclass should have common properties. In addition to this the derive class can have its own methods like "Swim()"...
In case of Abstract class we can define COMMON functionalities in super class and those can be used in the derived class where as in Interface we cant do that. ( this i would say as advantage of abstract class)
In case of Interface the derived class can implement any number of interface but restricted to extend only one abstract class (this i would say as advantage of Interface)
Thanks
Prasanna
Above answer was rated as good by the following members: nrganesh.java
RE: What is the use of abstract classes? How will we d...
Abstact classses are those classes which can have abstact as well as Method with body . we use Abstract classes becouse we wont ot implement the Polymorphism.yes we should prefer the abstarct class becouse it will give us the addtional method declaration in the class.
RE: What is the use of abstract classes? How will we d...
Use case will lead you to entities. These might be leading to is-A relationship. Such relationship is usually rooted with Abstract classes which provides polymorphism and also lead to application of many design patterns such as Abstract Factory, template, strategy and many others.
RE: What is the use of abstract classes? How will we d...
We use Abstract class and interface to enforce some rules to the classes which extends/implements. For example we can define a class say "Bird" and we can declare methods say "Fly()", "Walk()". This means whatever the class that is derived from Bird has to override or give definition for Fly() and Walk() and therefore we are making sure that all the derived classes follows or has the common functionalities. In other way the classes derived from superclass should have common properties. In addition to this the derive class can have its own methods like "Swim()"...
In case of Abstract class we can define COMMON functionalities in super class and those can be used in the derived class where as in Interface we cant do that. ( this i would say as advantage of abstract class)
In case of Interface the derived class can implement any number of interface but restricted to extend only one abstract class (this i would say as advantage of Interface)
RE: What is the use of abstract classes? How will we d...
The abstract class is a base class for a variety of classes that offers common members n methods. If we want to hold common properties for different classes then we use abstract class. If we need common functionalities among different classes then we use interfaces.