-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariables.java
More file actions
53 lines (40 loc) · 716 Bytes
/
Copy pathVariables.java
File metadata and controls
53 lines (40 loc) · 716 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
50
51
52
53
package com.optum.samar;
import java.io.PrintStream;
public class Variables {
private int a;
private int b;
public PrintStream out;
public static void main(String[] args) {
Variables v = new Variables();
v.setA(2);
v.setB(3);
int sum = v.sum();
System.out.println("Sum is " + sum);
Variables v2 = new Variables();
v2.setA(5);
v2.setB(10);
sum = v2.sum();
System.out.println("Sum is " + sum);
}
public int getA() {
return a;
}
public void setA(int a) {
if (a < 0) {
this.a = 0;
}
this.a = a;
}
public int getB() {
return b;
}
public void setB(int b) {
if (b < 0) {
this.b = 0;
}
this.b = b;
}
public int sum() {
return getA() + getB();
}
}