对于Person类,如果给成员变量name赋值
A: Person.name="老王";
B: p.name="老王";
C: p.setName("老王");
D: p.getName("老王");
A: Person.name="老王";
B: p.name="老王";
C: p.setName("老王");
D: p.getName("老王");
举一反三
- 阅读下面代码: Person 类: public class Person { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } } Servlet1: request.getSession().setAttribute("name","zhangsan"); Person p = new Person(); p.setName("lisi"); request.getSession().setAttribute("person",p); Servlet2: String name1 = (String)request.getSession().getAttribute("name"); Person p = (Person)request.getSession().getAttribute("person"); response.getWriter().write(name1); if(p!=null)response.getWriter().write(p.getName()); 浏览器先访问Servlet1,再去访问Servlet2,输出的结果是:()
- 分析下面的程序,输出的结果是? 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 ; } }
- 以下代码执行后的结果是: 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); } }
- 定义类的代码如下:class Person():def __init__(self,name):self.name=namedef show(self):print(self.name) A: p=Personp.show() B: p=Person()p.show('李思') C: p=Person('李思')p.show() D: p=Person('李思')show()
- 能将字符串存储到name数组中的选项有() A: char name[20], *p;p=name;gets(name); B: char name[20], *p;p=name;gets(p); C: char name[20], *p;p=name;scanf("%s",name); D: char name[20], *p;p=name;scanf("%s",p);