Usage of Abstract class and Interfaces

In Real time when we go for Abstract classes and when we go for Interfaces

Questions by sekhark.k

Showing Answers 1 - 24 of 24 Answers

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

  Was this answer useful?  Yes

geeky1

  • Jul 20th, 2008
 

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

sangamesh32

  • Aug 13th, 2008
 

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.

  Was this answer useful?  Yes

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.

  Was this answer useful?  Yes

rakesh_v27

  • Oct 14th, 2008
 

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.

  Was this answer useful?  Yes

dyy123

  • Nov 14th, 2008
 

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.

  Was this answer useful?  Yes

Sarje

  • Aug 13th, 2009
 

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.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions