Categories

Jun 17, 2019 in JAVA

Q: Difference between overriding and overloading in java?

Overriding Overloading

In overriding method names must be same In overloading method names must be same

Argument List must be same Argument list must be different atleast order of

arguments.

Return type can be same or we can return covariant

type. From 1.5 covariant types are allowed

Return type can be different in overloading.

We cant increase the level of checked exceptions.

No restrictions for unchecked exceptions

In overloading different exceptions can be thrown.

A method can only be overridden in subclass A method can be overloaded in same class or

subclass

Private,static and final variables cannot be

overridden.

Private , static and final variables can be

overloaded.

In overriding which method is called is decided at

runtime based on the type of object referenced at

run time

In overloading which method to call is decided at

compile time based on reference type.

Overriding is also known as Runtime polymorphism,

dynamic polymorphism or late binding

Overloading is also known as Compile time

polymorphism, static polymorphism or early

binding.

1 Answer

Jun 17, 2019

Overriding Overloading

In overriding method names must be same In overloading method names must be same

Argument List must be same Argument list must be different atleast order of

arguments.

Return type can be same or we can return covariant

type. From 1.5 covariant types are allowed

Return type can be different in overloading.

We cant increase the level of checked exceptions.

No restrictions for unchecked exceptions

In overloading different exceptions can be thrown.

A method can only be overridden in subclass A method can be overloaded in same class or

subclass

Click here to read more about JAVA
Click here to read more about Insurance

Related questions

Madanswer
Jun 16, 2019 in JAVA
Jun 16, 2019 in JAVA
Jun 17, 2019 in JAVA
...