when to use abstract class and when to use interface?

Answers were Sorted based on User's Feedback



when to use abstract class and when to use interface?..

Answer / surendra

Always prefer to interface until you are not sure the behavior
of operations.

chose the abstract class if you are sure for some common behaviors need to share of all objects.

Is This Answer Correct ?    0 Yes 0 No

when to use abstract class and when to use interface?..

Answer / arvind

If you have to implement all of the fuctionalities provided
by, then in this case you should use interfaces because
they force you to implement all of the methods.

on the other hand if you think you have to imlement few of
them , then better you use abstract class.

Is This Answer Correct ?    1 Yes 2 No

when to use abstract class and when to use interface?..

Answer / rod

the bowlingball example I put is when you combine the
abstract class ball with the interface bowlable .. a poor
example perhaps.. lets replace that with

a sock may implement a washable interface which can also be
implemented by cars, shirts, dishes... etc.. so why bother
with this. The reason is for future use as the system grows.
It is more likely that you will run into an object that
needs to be 'washed' then you can in fact call this method
without knowing the lower level details.

its more than just organising things that do or are acted
upon by the same conceptual action. It means that later you
can just use the method because the interface populates the
list of things you can choose from at code completion in the
editor ..for example.

Is This Answer Correct ?    3 Yes 6 No

when to use abstract class and when to use interface?..

Answer / jc

If you want give different implementation(behaviour) to
methods which are available in the interface go for
interface.
If you want give different implementation to particular
methods(that is only some methods which are not similar to
subclass)go for abstract class.

Is This Answer Correct ?    0 Yes 4 No

when to use abstract class and when to use interface?..

Answer / ram

Abstract class is used when and what methods are used
exactly while in interface,the methods are defined for
future use.

Is This Answer Correct ?    7 Yes 12 No

when to use abstract class and when to use interface?..

Answer / rod

Ram, your last post does not make sense, can you please post
again and say it differently.

The interface methods will naturally depend on the program
you are writing. read the links I referred to ...they are
well written and clear.

Is This Answer Correct ?    6 Yes 13 No

Post New Answer

More Core Java Interview Questions

Difference between an argument and a parameter?

10 Answers   Accounting, HCL, IBM, Quinnox,


i don't want fullforms of JDK an JVM i want definitions for them

2 Answers  


What is the ResourceBundle?

2 Answers   Elementus Technologies,


Why are global variables used?

0 Answers  


Explain pass by reference and pass by value?

8 Answers   IBM, Wipro,






What are the OOAD concepts in java explain with examples?

4 Answers   Aricent, CTS,


What is an infinite loop in java? Explain with an example.

0 Answers  


What is quick sort in java?

0 Answers  


what us Dyna action form?

4 Answers   Aithent Technologies,


What is static data type in java?

0 Answers  


What are the types of collections in java?

0 Answers  


What classes can be used to store arbitrary number of objects ?

1 Answers  


Categories