GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  J2EE  >  OOPS
Go To First  |  Previous Question  |  Next Question 
 OOPS  |  Question 7 of 31    Print  
What is the use of abstract classes? How will we decide in a scenario, whether we have to use abstract class or interface?

  
Total Answers and Comments: 20 Last Update: February 19, 2008     Asked by: Rajiv 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Prasanna Balaraman
 

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
  Sorting Options  
  Page 1 of 2   « First    1    2    >     Last »  
December 02, 2005 08:13:00   #1  
slp2683 Member Since: November 2005   Contribution: 1    

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.
 
Is this answer useful? Yes | No
December 03, 2005 09:30:01   #2  
imiten Member Since: December 2005   Contribution: 2    

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.
 
Is this answer useful? Yes | No
December 16, 2005 17:08:51   #3  
Prasanna Balaraman        

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)

Thanks

Prasanna


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
January 21, 2006 18:52:42   #4  
chandra reddy        

RE: What is the use of abstract classes? How will we d...

Thats exactly very good example.

Thank you very much prasanna

thanks

Chandra_mca2000@yahoo.com


 
Is this answer useful? Yes | No
March 13, 2006 11:15:42   #5  
japa2001in Member Since: March 2006   Contribution: 2    

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.
 
Is this answer useful? Yes | No
March 15, 2006 06:04:59   #6  
Gopi        

RE: What is the use of abstract classes? How will we d...

Both the Abstract Class and the Interface Class canot be Instansitiated


 
Is this answer useful? Yes | No
April 06, 2006 13:58:36   #7  
hmashruf Member Since: March 2006   Contribution: 32    

RE: What is the use of abstract classes? How will we d...

Hi,

At the same time abstract class cannot be final. I think it will be compilation error. Please correct me if I am wrong.

Never tried final interface and compile it. Did somebody? I think again compilation error.

With Best Regards

-ashruf


 
Is this answer useful? Yes | No
April 10, 2006 08:16:38   #8  
keshav        

in the real time environment when do we go for abstract class and when do we go interface ? can any one please reply me in this regard?

hi in the real time environment , when do we go for abstract class and when do we go for interfaces , can any one please revert back in this regard?

chennakeshava_r@gmail.com


 
Is this answer useful? Yes | No
April 11, 2006 10:11:29   #9  
Giridhar        

RE: What is the use of abstract classes? How will we d...

that's good example

Abstact class mainly used for default behaviour purpose.


 
Is this answer useful? Yes | No
April 15, 2006 12:55:35   #10  
Ravi Kumar        

Hi
What is the Exact difference bt Load Testing and Stress Testing and Performance Testing.
 
Is this answer useful? Yes | No
  Page 1 of 2   « First    1    2    >     Last »  


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape