-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathStaticKeyword.java
More file actions
42 lines (30 loc) · 1.13 KB
/
StaticKeyword.java
File metadata and controls
42 lines (30 loc) · 1.13 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
class CustomerA {
//static int counter = 100;
static int counter;
int id;
String name;
double balance;
static {
counter = 100;
System.out.println("Static block init...");
}
public CustomerA(String name, double balance) {
counter++;
this.id = counter;
this.balance = balance;
this.name = name;
}
}
public class StaticKeyword {
public static void main(String[] args) {
CustomerA c1 = new CustomerA("John", 45000.00);
System.out.println(c1.id + "," + c1.name + "," + c1.balance);
CustomerA c2 = new CustomerA("Shawn", 30000.00);
System.out.println(c2.id + "," + c2.name + "," + c2.balance);
System.out.println(c1.id + "," + c1.name + "," + c1.balance);
CustomerA c3 = new CustomerA("Max", 35000.00);
System.out.println(c3.id + "," + c3.name + "," + c3.balance);
System.out.println(c2.id + "," + c2.name + "," + c2.balance);
System.out.println(c1.id + "," + c1.name + "," + c1.balance);
}
}