Method overloading.

In this article,Method overloading is explained in detail with examples.
Two or more methods in a single class with same name and atleast one difference in the signature is known as method loading.
Signature means a number of arguments, the order of arguments and data type of arguments.
Ex
class A
{
---Data members---;
---Constructors----;
void m1(int,int){---}
void m1(float,float){---}
void m1(int,float){---}
void m1(float,int){---}
}
Total we are using parameterized constructors.
Ex
//program related to Method overloading.
class ExampleClass2
{
void exampleMethod()
{
System.out.println("Method with no arguments");
}
void exampleMethod(int i)
{
System.out.println("Method with 1argument I sis: "+i);
}
void exampleMethod(int i,int j)
{
System.out.println("Method with 2 arguments I is: "+i);
System.out.println("Method with 2 arguments J is: "+j);
}
}
class MethodOverloading
{
public static void main(String args[])
{
ExampleClass2 obj=new ExampleClass2();
obj.exampleMethod();
}
}
Output
MethodOverloading-no argument-Output-Javaform

Ex
//program related to method overloading.
class ExampleClass2
{
void exampleMethod()
{
System.out.println("Method with no arguments");
}
void exampleMethod(int i)
{
System.out.println("Method with 1argument I sis: "+i);
}
void exampleMethod(int i,int j)
{
System.out.println("Method with 2 arguments I is: "+i);
System.out.println("Method with 2 arguments J is: "+j);
}
}
class MethodOverloading
{
public static void main(String args[])
{
ExampleClass2 obj=new ExampleClass2();
obj.exampleMethod(10);
}
}
Output
MethodOverloading-1 argument-Output-Javaform

Ex
//program related to method overloading.
class ExampleClass2
{
void exampleMethod()
{
System.out.println("Method with no arguments");
}
void exampleMethod(int i)
{
System.out.println("Method with 1argument I sis: "+i);
}
void exampleMethod(int i,int j)
{
System.out.println("Method with 2 arguments I is: "+i);
System.out.println("Method with 2 arguments J is: "+j);
}
}
class MethodOverloading
{
public static void main(String args[])
{
ExampleClass2 obj=new ExampleClass2();
obj.exampleMethod(100,200);
}
}
Output
MethodOverloading-2 argument-Output-Javaform

Ex
//program related to Method overloading.
class Exampleclass2
{
void exampleMethod()
{
System.out.println("Method with no arguments");
}
void exampleMethod(int i)
{
System.out.println("Method with 1 argument I is: "+i);
}
void exampleMethod(int i,int j)
{
System.out.println("Method with 2 arguments I is: "+i);
System.out.println("Method with 2 arguments J is: "+j);
}
void exampleMethod(int i,int j,float k)
{
System.out.println("Method with 3 arguments I is: "+i);
System.out.println("Method with 3 arguments J is: "+j);
System.out.println("Method with 3 arguments k is: "+k);
}
}
class MethodOverloading
{
public static void main(String args[])
{
Exampleclass2 obj=new Exampleclass2();
obj.exampleMethod(100,200,35.87f);
}
}       
Output
MethodOverloading-3 arguments-output-Javaform
                              To get the code file use me.


Begin your career in Digital Marketing,What is digital marketing? Digital Marketing online course. It's an current evolving technology which can give support to establish your own startup through Digital Marketing.

Do check my new startup Surprise Planners in HyderabadLavish Surprises our services are surprise party planners in Hyderabadsurprise giftssurprise birthday party planners Hyderabad, Wedding anniversary surprisessurprise planners Hyderabad.

Hi Friends, Please comment down your views in the comment section below. Thank you...

No comments:

Connect with Us by Subscribing here for more Updates..!

* indicates required