-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverloading.java
More file actions
48 lines (36 loc) · 1.01 KB
/
Overloading.java
File metadata and controls
48 lines (36 loc) · 1.01 KB
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
// FUNCTION OVERLOADING
import java.util.Scanner; // input kay liye
// DONE
public class Overloading
{
int a = 0, b = 0; // these are data members
// Member functions
int sum() // object related
{
// the normal integer sum
return a + b;
}
int sum(int x, int y) // object related
{
// the normal integer sum
return x + y;
}
int sum(Overloading obj) // object related
{
// the normal integer sum
return obj.a + obj.b;
}
public static void main(String[] args)
{
Overloading halima = new Overloading(); // object made of main class
Scanner obj = new Scanner(System.in);
// PROMPT
System.out.print(" Enter the 1st Number : ");
halima.a = obj.nextInt();
System.out.print(" Enter the 2nd Number : ");
halima.b = obj.nextInt();
System.out.println(); // for spacing purposes
// OUTPUT
System.out.println(" Sum : " + (halima.sum(halima)));
}
}