Contents

测试代码高亮

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
class WaterSource{
private String s;
WaterSource(){
System.out.println("WaterSource()");
s = "constructed";
}
public String toString(){
return s;
}
}
public class SprinklerSystem {
private String name = "Alex";//Initializing at point of definition
private String sex;
private WaterSource wSource;
private double d;
public SprinklerSystem(){
System.out.println("In Sprinkler");
d = 1.0; //Initailizing in the constructor of class
wSource = new WaterSource();
}
public String toString(){
if (sex == null) { sex = "male"; }//Delayed initialization
return
"string" + "=" + name + " " +
"sex" + "=" + sex + " " +
"double" + "=" + d + " " +
"WaterSource" + "=" + wSource;
}
public static void main(String[] args){
SprinklerSystem sprinklers = new SprinklerSystem();
System.out.println(sprinklers);
}
}
comments powered by HyperComments
Contents
Fork me on GitHub