(06-06)分析如下所示的Java代码,其中this关键字的意思是(
)。
public class Test {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name; //this关键字所在的行
}
}
Class Main{
Public static void main(String []args){
Test T1 = new Test();
T1.setname(“zhangsan”);
}
}
)。
public class Test {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name; //this关键字所在的行
}
}
Class Main{
Public static void main(String []args){
Test T1 = new Test();
T1.setname(“zhangsan”);
}
}
举一反三
- 分析如下所示的Java代码,其中this关键字的意思是( )。 public class Test { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; //this关键字所在的行 } }
- 分析下面的程序,输出的结果是? public class Test { public static void main(String[] args) { final Person p = new Person("张三", 23); p.setName("李四"); p.setAge(24); System.out.println(p); } } class Person { private String name; private int age; public Person() { super(); } public Person(String name, int age) { super(); this.name = name; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "我的姓名是:" + name + ",我的年龄是:" + age ; } }
- 请阅读下面的程序 class Test { private static String name; static { name = "World"; System.out.print (name); } public static void main(String[] args) { System.out.print("Hello"); Test test = new Test(); } } 下列选项中,程序运行结果是
- 下列程序的运行结果是( )class Demo{private String name;Demo(String name){this.name = name;}private static void show(){System.out.println(name)}public static void main(String[] args){Demo d = new Demo(“lisa”);d.show();}}
- 以下代码执行后的结果是: public class Person { String name = “小芳”; public Person(String name) { name = “小兰”; } public void show() { this.name = “小翠”; } public static void main(String[] args) { Person p = new Person(“小凤”); System.out.print(p.name); p.show(); System.out.print(p.name); } }