Method Overloading In Java Example

Chapter: Inheritance Last Updated: 20-07-2016 03:21:29 UTC

Program:

            /* ............... START ............... */
                
public class JavaMethodOverloading {
	void val(int a, int b) {
		System.out.println(a + b);
	}

	void val(int a, int b, int c) {
		System.out.println(a + b + c);
	}

	public static void main(String args[]) {
		JavaMethodOverloading obj = new JavaMethodOverloading();
		obj.val(10,20,30);
		obj.val(20, 20);

	}
}
                /* ............... END ............... */
        

Output

60
40

Notes:

  • If a class have multiple methods by same name but different parameters,it is known as Method Overloading.
  • Method overloading is one of the ways through which java supports polymorphism.
  • If two or more method have same name and same parameter list but differs in return type are not said to be overloaded method.

Tags

Method Overloading, Java

Similar Programs Chapter Last Updated
Java Final Class Inheritance 02-08-2017
Java Final Method In Inheritance Inheritance 02-08-2017
Java Multilevel Hierarchical Inheritance Inheritance 01-08-2017
Java Super To Invoke Parent Class Method Inheritance 31-07-2017
Java Super To Invoke Parent Class Constructor Inheritance 30-07-2017
Static And Dynamic Binding In Java Inheritance 24-03-2017
Java Overloaded Method To Print Array Inheritance 03-09-2016
Dynamic Method Dispatch In Java Example Inheritance 19-06-2016
Abstract Class In Java Example Inheritance 20-07-2016
Method Overriding In Java Example Inheritance 20-07-2016
Inheritance And Constructors In Java Inheritance 20-07-2016
Multilevel Inheritance In Java Example Inheritance 22-09-2018
Super() In Java Example Inheritance 14-07-2016
Inheritance In Java Example Inheritance 20-07-2016

1