forked from utkarsh-shekhar/basic-programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverload.java
More file actions
49 lines (39 loc) · 958 Bytes
/
Overload.java
File metadata and controls
49 lines (39 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* This program demonstrate the method overloading
*/
class OverloadDemo
{
void test()
{
System.out.println("No parameters");
}
/* Overload the test for one integer parameter */
void test(int a)
{
System.out.println("a : " + a);
}
/* Overload the test for two integer parameters */
void test(int a, int b)
{
System.out.println("a is " + a + "\nb is " + b);
}
/* Overload the test for a double parameter */
double test(double a)
{
System.out.println("double a : " + a);
return a*a;
}
}
class Overload
{
public static void main(String args[])
{
OverloadDemo ob = new OverloadDemo();
double result;
/* all the version of method test() */
ob.test();
ob.test(100);
ob.test(100, 200);
result = ob.test(123.25);
System.out.println("Result of ob.test(123.25) is " + result);
}
}