what is the difference between abstract class and
Interface?where we can use it in realtime projects?

Answer Posted / chitij mehrotra

1 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 ?    54 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How many threads can java run?

561


What are the states of thread in java?

517


what do you mean by marker interface in java?

547


What is the benefit of lambda expressions?

497


What is Java Annotations?

557






What kind of variables a class can consist of?

637


How do you add spaces in java?

514


What function extracts specified characters from a string?

567


How many types of flags are there?

523


What are thread safe functions?

514


What is a protected void?

506


Are arrays classes in java?

535


What is an immutable object? How do you create one in java?

602


What is super?

585


In a class implementing an interface, can we change the value of any variable defined in the interface?

559