what is the difference between abstract class and
Interface?where we can use it in realtime projects?
Answer Posted / varun kumar
1.interface contains methods that must be abstract;
abstract class may contain concrete methods.
2.interface contains variables that must be static and
final; abstract class may contain non-final and final
variables.
3.members in an interface are public by default, abstract
class may contain non-public members.
4.interface is used to "implements"; whereas abstract class
is used to "extends".
5.interface can be used to achieve multiple inheritance;
abstract class can be used as a single inheritance.
6.interface can "extends" another interface, abstract class
can "extends" another class and "implements" multiple
interfaces.
7.interface is absolutely abstract; abstract class can be
invoked if a main() exists.
8.interface is more flexible than abstract class because
one class can only "extends" one super class,
but "implements" multiple interfaces.
9.If given a choice, use interface instead of abstract
class.
| Is This Answer Correct ? | 3 Yes | 1 No |
Post New Answer View All Answers
Can we override final method?
Does printwriter create a file?
How do you compare two objects?
What is isa relationship?
Why can't you declare a class as protected?
What is type conversion in java?
What is initial size of arraylist in java?
Can we clone singleton object in java?
Is java owned by oracle?
What is your platform’s default character encoding?
What is r * in math?
Can we have any code between try and catch blocks?
What is the difference between throw and throws in java?
How does linkedlist work in java?
What is the difference between Java1.4 and Java1.5