MainMenu

Home Core Java Overview Maven Tutorials

Sunday, 15 January 2017

Method Overloading in Java with Example



For Video Tutorial : Move on Youtube Channel


Note : Select the playlist as per your need & move with number sequence


Method Overloading in java with example


Video Tutorial for this Atricle : CLICK HERE



When there is more than one method with same name & different parameter with in a class then it is known as Method overloading
Also these methods can be accessed by objects using appropriate parameter.

Example : Below code have two method with same name but different parameter & will be accessed by object.
package chandan_test1;
class Chandan2
{
public void sum(int a, int b)
{
System.out.println("Your sum is : " +(a+b));
}
public void sum(int a, int b, int c)
{
System.out.println("your sum is : "+(a+b+c));
}
}
public class Chandan1
{
public static void main(String args[])
{
Chandan2 obj = new Chandan2();
obj.sum(3,5);
obj.sum(4,6,8);
}
}
Output:
Your sum is : 8
your sum is : 18

Tags :Method overloading in java, what is method overloading in java?

No comments:

Post a Comment