when to use abstract class and when to use interface?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is method overriding in java ?

649


What class allows you to read objects directly from a stream in java programming?

504


What are the characteristics of Final,Finally and Finalize keywords.

692


What is files manifesting?

1720


Explain why wait(), notify() and notifyall() methods are in object class rather than in the reading class?

556






Can an arraylist be empty?

562


What is composition in java?

716


What will be the default values of all the elements of an array defined as an instance variable?

544


Can long be null in java?

540


Convert a BST into a DLL and DLL to BST in place.

660


What are encapsulation, inheritance and polymorphism?

522


What is null data type?

532


Which java version is latest?

531


What is difference between printf and scanf?

514


What is a condition in programming?

550