You are on page 1of 3

Difference Between Inheritance and Polymorphism in Java

Inheritance Polymorphism

Definition It allows a class to use the It allows an object to behave


properties and methods in multiple ways
of a superclass
Implementation occurs in class level occurs in method level

Usage It provides code It allows calling methods


reusability accordingly at compile time
and runtime
1). Polymorphism applies to overriding, not to overloading.
2). Overriding is a run-time concept while overloading is a compile-time concept.
There are many differences between abstract class and interface that are given below.

Abstract class Interface

1) Abstract class can have abstract Interface can have only


and non-abstract methods. abstract methods. Since Java 8, it can
have default and static methods also.

2) Abstract class doesn't support Interface supports multiple


multiple inheritance. inheritance.

3) Abstract class can have final, Interface has only static and final
non-final, static and non-static variables.
variables.

4) Abstract class can provide the Interface can't provide the


implementation of interface. implementation of abstract class.

5) The abstract keyword is used to The interface keyword is used to declare


declare abstract class. interface.

6) An abstract class can extend An interface can extend another Java


another Java class and implement interface only.
multiple Java interfaces.

7) An abstract class can be An interface can be implemented using


extended using keyword "extends". keyword "implements".

8) A Java abstract class can have Members of a Java interface are public by
class members like private, protected, default.
etc.

9)Example: Example:
public abstract class Shape{ public interface Drawable{
public abstract void draw(); void draw();
} }

Simply, abstract class achieves partial abstraction (0 to 100%) whereas interface achieves
fully abstraction (100%)

You might also like