CodesJava

Easy learning with example program codes

difference between method overloading and overriding in java?


Method overloading

Method overloading is the way of implementing static/compile time polymorphism in java. Method overloading means more than one methods in a class with same name but different parameters. Parameters can be differing in types, numbers or order. Compiler resolve method call by matching method signature at compile time, that’s why it is known as static or compile time polymorphism. It is also known as static binding.

Ways to implement method overloading in java:

  1. Parameters differ in types.
  2. Parameters differ in number.
  3. Parameters differ in order.

 

Method overriding

If a subclass provides a method with the same signature (name and parameter) as in its super class, then subclass overrides the method of its super class. This process of overriding a super class method by subclass is known as method overriding.

Conditions for method overriding:

  1. Method in subclass must have same signature as in its super class.
  2. Two classes must follow IS-A relationship.

 

Method Overloading Method Overriding
Method overloading increases the readability of the program. Method overriding provides the specific implementation of the method that is already provided by its super class.
Method overloading is occurs within the class. Method overriding occurs in two classes that have IS-A relationship.
 Parameter must be different. Parameter must be same.

 

Java interview questions on method overloading and overriding

Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki