下列java程序的输出结果为____。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
public
class
Example{
String str=
new
String(
"hello"
);
char
[]ch={
'a'
,
'b'
};
public
static
void
main(String args[]){
Example ex=
new
Example();
ex.change(ex.str,ex.ch);
System.out.print(ex.str+
" and "
);
System.out.print(ex.ch);
}
public
void
change(String str,
char
ch[]){
str=
"test ok"
;
ch[
0
]=
'c'
;
}
}
|
数组和对象都是传递引用。
画内存图
左侧为栈,右侧为堆