引用变量的指向可以是多个吗
在父类对象调用成员方法中改变成员变量(引用变量的指向)后,是一个引用变量可以同时指向两个地址吗
public class Test {
String name="Tom";
public Test(String name){
name=name;
}
public static void main(String [] args){
Test t = new Test("Jack");
System.out.println(t.name);
}
}
A. null
B. Tom
C. Jack
D. " "
正确答案:B
[解决办法]
先教如何贴代码:
String str = "abc";
public class Test {
String name = "Tom";
public Test(String otherName) {
name = otherName;
}
public static void main(String[] args) {
Test t = new Test("Jack");
System.out.println(t.name);
}
}
public class Test {
String name = "Tom";
public Test(String name) {
this.name = name;
}
public static void main(String[] args) {
Test t = new Test("Jack");
System.out.println(t.name);
}
}