what is the difference between abstract class and
Interface?where we can use it in realtime projects?
Answer Posted / sachi
A class may inplement several interfaces. A
class may
extend only one abstract class.
2 An interface can have only abstract methods. An
abstract
class can have both abstract methods and concrete methods.
At one abstract method in the abstract class.
3 Interfaces cannot have constructors. Abstract
class can
have constructors.
4 Only static final variables are allowed to be
decelared.
Both static and instance variables are allowed.
5 All decelared methods are implicitly public. Can
have any
kind of methods.
6 We should initialize variables in an interface. Not
necessary to initialize variables in an abstract class.
7 In the case of interface you can make any class in
the
hierarchy. In the case of abstract class you know the
class
hierarchy in advance.
8 An interface implementation may be added to any
existing
third party class. A third party class must be
rewritten to
extend only from the abstract class.
9 Interfaces can be implemented by classes that are
not
related to one another Abstract classes are used only when
there is a “is-a” type of relationship between the classes.
| Is This Answer Correct ? | 18 Yes | 5 No |
Post New Answer View All Answers
Can we overload final method in java?
What is ‘is-a ‘ relationship in java?
Explain heap sort?
What are the classes of java?
Can we have 2 main methods in java class?
What does \ mean in regex?
What are the three parts of a lambda expression? What is the type of lambda expression?
What is constructor chaining in java?
how can you catch multiple exceptions in java?
Which are different kinds of source code?
What is array sorting in java?
what is the swingutilities.invokelater(runnable) method for? : Java thread
Given a singly linked list, how will you print out its contents in the reverse order? Can you do it with consuming any extra space?
What is the use of string and stringbuffer?
Difference between static synchronization vs. Instance synchronization?