Skip to content

Commit ee1303c

Browse files
authored
Add files via upload
1 parent e651c18 commit ee1303c

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

Methods/MethodOverloading1.java

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
class Overload
2+
{
3+
void test()
4+
{
5+
System.out.println("No parameter");
6+
7+
}
8+
void test(int a)
9+
{
10+
System.out.println("a="+a);
11+
}
12+
void test (int a,int b)
13+
{
14+
System.out.println("a="+a);
15+
System.out.println("b=" + b);
16+
17+
}
18+
double test(double a)
19+
{
20+
return a*a;
21+
}
22+
void test(byte b)
23+
{
24+
System.out.println("byte b="+b);
25+
}
26+
void test(String s)
27+
{
28+
System.out.println("String:"+s);
29+
}
30+
}
31+
class MethodOverloading1 {
32+
public static void main(String[] args) {
33+
byte a =8;
34+
Overload obj=new Overload();
35+
obj.test(a);//goes to method with byte argument
36+
obj.test(250);//int
37+
System.out.println("Square of double a:"+obj.test(7.5));//double
38+
obj.test("Hello");//String
39+
obj.test('A');// Since char is
40+
// not available, so the datatype
41+
// higher than char in terms of
42+
// range is int.
43+
System.out.println("Square of float a:" + obj.test(5f));// double
44+
45+
}
46+
}

0 commit comments

Comments
 (0)