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?

Showing Answers 1 - 9 of 9 Answers

Liramu

  • Apr 21st, 2006
 

Interface is the one which can be implemented by many number of methods in different classes as it requires, so there may be a chance that u may have some functionality which wil be need for many methods , in that case u u use interface to declare

Abstract class is the one which can implement more than one of this kind of interfaces but only the conditon is that all of its methods sud be implemented in the subclasses

  Was this answer useful?  Yes

sachin

  • Apr 22nd, 2006
 

Interface is implemented by many classes they are place in anywhere but abstract cannot be inherited by multiple classes. Interfaces contain the abstract methods so interface is very efficient than abstract.

  Was this answer useful?  Yes

kiran

  • Apr 26th, 2006
 

In the Interfaces we r Implemeting all the methods but in the case of Abstract classes there is no need to implemet all the methods.In the abstract class some methods have the body

  Was this answer useful?  Yes

Deepthik

  • Apr 26th, 2006
 

 In java like C++ there is no support for multiple inheritance. in order to have multiple inheritance we go for interfaces, An interfaces can extends multiple inferaces, when we want the feature of multiple inheriatance we go for interfaces.

Abstract class support single inheritance, here in abstract class when we want to define some methods as common methods, we can use non abstract methods but a class can extend atmost only one abstract method.

  Was this answer useful?  Yes

An abstract class can contain 0 or more abstract methods and 0 or more concrete methods (methods which are implemented) whereas an interface can not contain any concrete methods and can contain 0 or more abstract methods.

If we have to define a class which should have some concrete methods that define the required operations, and also some abstact methods that should be overridden by the derived classes, then  we should declare that class as abstract.

If we doesn?t have to define any operations (methods) and we have only the method signatures which must be overridden, then we go for interfaces. Since interfaces doesn?t contain any concrete methods i.e, interface doesn?t have any implemetation , it can be used for multiple inheritance.

  Was this answer useful?  Yes

SrinivaS

  • May 30th, 2006
 

Hi,

This is the situation .

A programmer uses abstract class when these are some common features
Shared by all the objects.

A programmer writes an interface when every feature should be implemented
Differently for different objects and the implementation is left to third party vendor.

ok bye....

keeps smiling and mailing

bora_srinivasarao@yahoo.co.in

note:if any want java faq's ,java materials,e-books just send a mail to my id

if any one have doubts regardin java just send mail to my id.if possible i will try.

  Was this answer useful?  Yes

Dannyboy

  • Jun 6th, 2006
 

I suggest you to read "Head First Design Patterns" Strategy Pattern.You'll get clear idea.

  Was this answer useful?  Yes

we use abstract class when we want specify common features of a group of objects, when we dont know how to implement them.

we use interfaces when we know features of a group of objects, but we dont know how to implement them in a new environment, then we leave the implementation to 3rd part vendor.

ex: in EJB in remote interface we specify the business methods, but we implement these methods in bean class.

  Was this answer useful?  Yes

we use the abstract class when we want to specify common featurs of  a group of objects, when we dont how to implement them.

we use interfaces, when we know the features, but we dont know how to implement them in a new environment. so then we leave the implementation to 3rd party vendor.

ex: in EJB we we specify the methods in remote interface, but we implement them in bean class.

 by sadashiva rao t

  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