类中的静态变量赋值和调用

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
public class test {
public static void main(String[] agrs) {
new a();
b classB = new b();
classB.init();
classB.action();
c classC = new c();
classC.cAction();
}

public static class a {
public static String[] ha = new String[2];
}

public static class b {
private String mHa;

public void init() {
this.mHa = a.ha;
this.mHa[0] = "NONE0";
this.mHa[1] = "NONE1";
}

public void action() {
this.mHa[0] = "Hello0";
this.mHa[1] = "Hello1";
}
}

public static class c {
public void cAction() {
for (String item : a.ha) {
System.out.println(item + "\n");
}
}
}
}
// 结果为
// Hello0
// Hello1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public class test {
public static void main(String[] agrs) {
a First = new a();
First.one = "ha";
First.two = "hahaha";
First.three = "Emmm...";
a Second = First;
Second.one = "Cry...";
System.out.println(First.one);
}

public static class a {
public String one;
public String two;
public String three;
}
}
// 结果为 "Cry..."

PHP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
class a {
public $one;
public $two;
public $three;
}

$First = new a();
$First->one = "ha";
$First->two = "hahaha";
$First->three = "emmmmm.....";

$Second = $First;
$Second->one = "cry...";

echo $First->one;
// 结果为 "cry..."
本站文章除注明转载外均为原创,未经允许不要转载哇. ヾ(゚ー゚ヾ) http://qwqaq.com/78f87e97.html
分享到