What is Method Overloading in java:
========================
Overloading means same method name with different arguments is called over loading.
If a class have multiple methods by same name but different parameters, it is called method overloading.
========================
Overloading means same method name with different arguments is called over loading.
If a class have multiple methods by same name but different parameters, it is called method overloading.
Argument lists could differ in –
1. Number of parameters.
2. Data type of parameters.
3. Sequence of Data type of parameters.
1. Number of parameters.
2. Data type of parameters.
3. Sequence of Data type of parameters.
Method overloading is also known as Static Polymorphism.
//Example on method overloading
package blog;
public class OverloadDemo {
public void test1() {
System.out.println("no argument method");
}
public void test1(int a) {
System.out.println("single argument method" + a);
}
public void test1(int a, String s) {
System.out.println("two argument method" + a + "....." + s);
}
public static void main(String[] args) {
OverloadDemo overloadDemo = new OverloadDemo();
overloadDemo.test1();
overloadDemo.test1(10);
overloadDemo.test1(20, "selenium");
}
}
No comments:
Post a Comment