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
Can we declare the main method of our class as private?
Break statement can be used as labels in java?
What is the difference between class & structure?
What is a numeric literal?
Difference between object instantiation and construction ?
Can we convert integer to string in java?
What are pass by reference and pass by value?
What is the biggest integer?
What is type safety in java?
What are the types of exceptions?
What class allows you to read objects directly from a stream?
Can we use this () and super () in a method?
What is the difference between static and global variables and also define what are volatile variables?
Difference between ‘is-a’ and ‘has-a’ relationship in java?
What is implicit object in java?