Difference between Interface and Abstract Class

Compare Interface with Abstract Class

Features

Interface

Abstract Class

Inheritance

A class may inherit several interfaces.

A class may inherit only one abstract class.

Code

An interface contains only signature but no code

An abstract class can contain complete, default code and/or just signature that have to be overridden.

Access Modifiers

An interface cannot have access modifiers

An abstract class can contain access modifiers

Defines

Interfaces are used to define the peripheral abilities of a class

Abstract class defines the core identity of a class and there it is used for objects of the same type.

Homogeneity

If various implementations only share method signatures then it is better to use Interfaces.

If various implementations are of the same kind and use common behaviour or status then abstract class is better to use.

Fields

No fields can be defined

Fields can be defined

1 comment:

Anonymous said...

Good help..

Popular Posts