Java 106 - 107 - Method Overloading and Constructor, Constructor Overlaoding TP
Java 106 - 107 - Method Overloading and Constructor, Constructor Overlaoding TP
Output:
22
33
Note :- In this example, we are creating static methods so that we don't need to
create instance for calling methods
Output:
22
24.9
Exercise:- Program to show - Method Overloading is not possible by
changing the return type of method only.
class Adder{
static int add(int a,int b){return a+b;}
static double add(int a,int b){return a+b;}
}
class TestOverloading3{
public static void main(String[] args){
System.out.println(Adder.add(11,11));//ambiguity
}}
Output:
class TestOverloading4{
public static void main(String[] args){System.out.println("main with String[]");}
public static void main(String args){System.out.println("main with String");}
public static void main(){System.out.println("main without args");}
}
Output:
Output:
0 null
0 null
Output:
111 Karan
222 Aryan
Output:
111 Karan 0
222 Aryan 25
0 null 0