class Person{ static{ System.out.println(name); } private static String name = "hello"; } class Demo{ public static void main(String[] args){ Person p = null; } }
举一反三
- 下列程序的运行结果是( )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();}}
- 阅读下列的程序 class Person{ static{ System.out.println("static") } Person(){ System.out.println("构造") } } class Demo{ public static void main(String[] args){ Person p = new Person(); } } 下列选项中,程序的运行结果是()
- 以下代码执行后的结果是: 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); } }
- 下列ABCD注释标注的哪行代码有错public class Demo { public static void main(String args[]) { System.out.println("Java"); system.out.println("hello"); System.out.println("你好"); } } A: public class Demo B: public static void main(String args[]) C: system.out.println("ok"); D: System.out.println("您好");
- 请阅读下面的程序 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(); } } 下列选项中,程序运行结果是