• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 522
  • Last Modified:

Explain Difference Between Interface and abstract class

Explain Difference Between Interface and abstract class
Manikandan Thiagarajan
Manikandan Thiagarajan
  • 3
1 Solution

* Main difference is methods of a Java interface are implicitly abstract and cannot have implementations. A Java abstract class can have instance methods that implements a default behavior.
* Variables declared in a Java interface is by default final. An  abstract class may contain non-final variables.
* Members of a Java interface are public by default. A Java abstract class can have the usual flavors of class members like private, protected, etc..
* Java interface should be implemented using keyword “implements”; A Java abstract class should be extended using keyword “extends”.
* An interface can extend another Java interface only, an abstract class can extend another Java class and implement multiple Java interfaces.
* A Java class can implement multiple interfaces but it can extend only one abstract class.
* Interface is absolutely abstract and cannot be instantiated; A Java abstract class also cannot be instantiated, but can be invoked if a main() exists.
* In comparison with java abstract classes, java interfaces are slow as it requires extra indirection.



interface is a collection of methods which need to be implemented by any class which cliams to implement the interface

abstract class is a class which has one or more methods which were not implemented and should be implemenetd in the
non-abstract sub-class of this class

so those are in fact very different  entities.

interface does not include any iomplementation of any methods - only signatures
which need to be followed by implmeneting classes

abstract class can have implementation of all methods with the exception of one
and abstrcat class can have instance variable and everything

interfcae can have only method signtures and constants and nothing else

Basically interface is much more abstract thing - it just specifies certain number of brehaviours
taht the object should demonstrate, otherwise it does not specify much about the actual
"meat" of the object

Abstract class on the contrary will often specify almost everything about the object, but say one or two
behaviors leaves open, so that some subclasses of this abstract class implement these behaviors in one way and other
suvbclasses  - in another way

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now