1
2
3
4
5
6
7
8
9
10
11
|
public
class
Test1 {
public
static
void
main(String[] args) {
int
n =
3
;
System.out.println(
"Before change, n = "
+ n);
changeData(n);
System.out.println(
"After changeData(n), n = "
+ n);
}
public
static
void
changeData(
int
nn) {
n =
10
;
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
|
public
class
Test2 {
public
static
void
main(String[] args) {
StringBuffer sb =
new
StringBuffer(
"Hello "
);
System.out.println(
"Before change, sb = "
+ sb);
changeData(sb);
System.out.println(
"After changeData(n), sb = "
+ sb);
}
public
static
void
changeData(StringBuffer strBuf) {
strBuf.append(
"World!"
);
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
public
class
Test3 {
public
static
void
main(String[] args) {
StringBuffer sb =
new
StringBuffer(
"Hello "
);
System.out.println(
"Before change, sb = "
+ sb);
changeData(sb);
System.out.println(
"After changeData(n), sb = "
+ sb);
}
public
static
void
changeData(StringBuffer strBuf) {
strBuf =
new
StringBuffer(
"Hi "
);
strBuf.append(
"World!"
);
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
public
class
Test4 {
public
static
void
main(String[] args) {
StringBuffer sb =
new
StringBuffer(
"Hello "
);
System.out.println(
"Before change, sb = "
+ sb);
changeData(sb);
System.out.println(
"After changeData(n), sb = "
+ sb);
}
public
static
void
changeData(StringBuffer strBuf) {
StringBuffer sb2 =
new
StringBuffer(
"Hi "
);
strBuf = sb2;
sb2.append(
"World!"
);
}
}
|
1
2
3
4
5
6
7
8
9
10
11
|
public
class
Test1 {
public
static
void
main(String[] args) {
Deng l = new Deng();
l.setName("AnimTim");
System.out.println(
"Before change, Nmae= "
+ l.getName());
changeData(l);
System.out.println(
"After changeData(Deng), Name = "
+ l.getName());
}
public
static
void
changeData(Deng d
) {
d.setName("ssss");
}
}
|