-
Notifications
You must be signed in to change notification settings - Fork 0
/
static.java
55 lines (34 loc) · 1.24 KB
/
static.java
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
54
55
class Thing {
public final static int LUCKY_NUMBER = 7;
public String name;
public static String description;
public static int count = 0;
public int id;
public Thing() {
id = count;
count++;
}
public void showName() {
System.out.println("Object id: " + id + ", " + description + ": " + name);
}
public static void showInfo() {
System.out.println(description);
// Won't work: System.out.println(name);
}
}
public class App {
public static void main(String[] args) {
Thing.description = "I am a thing";
Thing.showInfo();
System.out.println("Before creating objects, count is: " + Thing.count);
Thing thing1 = new Thing();
Thing thing2 = new Thing();
System.out.println("After creating objects, count is: " + Thing.count);
thing1.name = "Bob";
thing2.name = "Sue";
thing1.showName();
thing2.showName();
System.out.println(Math.PI);
System.out.println(Thing.LUCKY_NUMBER);
}
}