请阅读程序,在空白处填写正确的代码,使getInstance()方法返回一个Person对象。
public class Person {
public static _______ getInstance() {
return new Person();
}
}
public class Person {
public static _______ getInstance() {
return new Person();
}
}
举一反三
- 阅读下列的程序 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{ 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{ 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 {private int a;public int change(int m){ return m; }}public class Teacher extends Person {public int b;public static void main(String arg[]){Person p = new Person();Teacher t = new Teacher();int i;// point x}}在 // point x安排哪个语句合法?
- 请阅读下面的程序,在空白处填写正确的代码,令代码实现方法的重载。public class Demo {public static int sum(int a, int b) {return a + b;}public static float sum(int a, ____ b) {return a + b;}}