GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  Next Question 
 Core Java  |  Question 485 of 502    Print  
Usage of Abstract class and Interfaces
In Real time when we go for Abstract classes and when we go for Interfaces


  
Total Answers and Comments: 8 Last Update: August 13, 2009     Asked by: sekhark.k 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: geeky1
 
Depends on the design consideration. If one wants the design  to be flexible then go for the interface else abstract class.
The abstract class can contain default implementation which is inherited by the subclasses by default. If you are looking for performance then abstract class is the best choice

Above answer was rated as good by the following members:
pravinsharma, alok2009
July 16, 2008 09:43:04   #1  
GMadhavaReddy222 Member Since: July 2008   Contribution: 3    

RE: Usage of Abstract class and Interfaces
In realtime If we want to provide some of the features to lower developers then we will for abstract class and If we want to provide complete features to lower developers then we will go for Interface
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 2Overall Rating: -2    
July 20, 2008 08:13:20   #2  
geeky1 Member Since: July 2008   Contribution: 2    

RE: Usage of Abstract class and Interfaces
Depends on the design consideration. If one wants the design to be flexible then go for the interface else abstract class.
The abstract class can contain default implementation which is inherited by the subclasses by default. If you are looking for performance then abstract class is the best choice

 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
August 13, 2008 07:03:54   #3  
sangamesh32 Member Since: August 2008   Contribution: 3    

RE: Usage of Abstract class and Interfaces
Abstract class means partial implementation which means he cannot directly use properties of this class i.e he has to inherit it and use the class and also allowed to provide extra properties. One real time use of abstract class is it can be used as a Adapter class.

Interfaces are open for implementation to use interfaces he has to provide implementaion to all methods. i.e interfaces are just specification which states what to do not how they are done.

 
Is this answer useful? Yes | No
October 01, 2008 04:26:49   #4  
shweta.suryanarayanan Member Since: September 2008   Contribution: 2    

RE: Usage of Abstract class and Interfaces

When we are aware of the method signature that the sub classes would be using and we want the subclasses to use a default behaviour of the base class we should use an abstract class as base class and implement the default behaviour there.

But if we are aware of only the method signatures and not the way each subclass wants to implement the behaviour we should go in for an interface.


 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
October 04, 2008 05:54:28   #5  
pawan kumar upadhyay Member Since: September 2008   Contribution: 1    

RE: Usage of Abstract class and Interfaces
If you want to write down the constructor then you should use the abstract class other wise use interface.
 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
October 14, 2008 01:22:53   #6  
rakesh_v27 Member Since: April 2008   Contribution: 1    

RE: Usage of Abstract class and Interfaces
Abstract class is a class that contain abstract methods.And it contain concrete methods and abstract methods.When we use constructor in our program abstract class can be used.

Interface is a specification of method prototypes.We can create an object to implementation class.In a program there is a different implementations we can use interface.

 
Is this answer useful? Yes | No
November 14, 2008 09:23:23   #7  
dyy123 Member Since: November 2008   Contribution: 1    

RE: Usage of Abstract class and Interfaces
When you don't want to expose the implementation of the methods then you can use the Interface. Abstract class is will have some methods implemented and some unimplemented.
 
Is this answer useful? Yes | No
August 13, 2009 05:34:50   #8  
Sarje Member Since: August 2009   Contribution: 62    

RE: Usage of Abstract class and Interfaces
If you want to create only abstract methods in a class then use interface and if you want to create some of the methods as abstract and some as concrete then use abstract class.
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape