阅读下面的代码: class Person{ void say(){ System.out.println("hello"); } } class Example{ public static void main(String[] args){ Person p1 = new Person(); Person p2 = new Person(); p2.say(); p1.say(); p2=null; p2.say(); } } 下列选项中,哪个是程序的输出结果?()
举一反三
- 请阅读下面的程序代码,选择正确的运行结果 Class Person{ void say(){ System.out.println(“hello”); } } class Example{ public static void main(String[] args){ Person p2 = new Person(); Person p1 = new Person(); p1.say(); p2.say();} }
- 阅读下列的程序 class Person{ static{ System.out.println("static") } Person(){ System.out.println("构造") } } class Demo{ public static void main(String[] args){ Person p = new Person(); } } 下列选项中,程序的运行结果是()
- class Person{ static{ System.out.println(name); } private static String name = "hello"; } class Demo{ public static void main(String[] args){ Person p = null; } }
- 以下代码执行后的结果是: 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); } }
- 阅读下面代码: 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,输出的结果是:()