以下程序的调试结果为?
public class Outer{
public String name = "Outer";
public static void main(String argv[]){
Inner i = new Inner();
i.showName();
}
private class Inner{
String name =new String("Inner");
void showName(){
System.out.println(name);
}
}
}
A.输出结果 Outer
B.输出结果 Inner
C.编译错误,因Inner类定义为私有访问
D.在创建Inner类实例的行出现编译错误
第1题:
public class Pet{ private String name; public Pet(){ System.out.print(1); } public Pet(String name){ System.out.print(2); } } public class Dog extends Pet{ public Dog(String name){ System.out.print(3); } } 执行new Dog(“棕熊”);后程序输出是哪项?()
第2题:
public class Pet{ private String name; public Pet(String name){ this.name = name; } public void speak(){ System.out.print(name); } } public class Dog extends Pet{ public Dog(String name){ super(name); } public void speak(){ super.speak(); System.out.print(“ Dog ”); } } 执行代码 Pet pet = new Dog(“京巴”); pet.speak(); 后输出的内容是哪项?()
第3题:
public class Employee{ private String name; public Employee(String name){ this.name = name; } public String getName(){ return name; } } public class Manager extends Employee{ public Manager(String name){ System.out.println(getName()); } } 执行语句new Manager(“smith”)后程序的输出是哪项?()
第4题:
public class Employee{ private String name; public Employee(String name){ this.name = name; } public void display(){ System.out.print(name); } } public class Manager extends Employee{ private String department; public Manager(String name,String department){ super(name); this.department = department; } public void display(){ System.out.println( super.display()+”,”+department); } } 执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?()
第5题:
public class Pet{ private String name; public Pet(){ System.out.print(1); } public Pet(String name){ System.out.print(2); } } public class Dog extends Pet{ public Dog(){ System.out.print(4); } public Dog(String name){ //这里隐藏了一句代码:super.pet(); this(); System.out.print(3); } } 执行new Dog(“棕熊”);后程序输出是哪项?()
第6题:
public class Pet{ private String name; public Pet(){ System.out.print(1); } public Pet(String name){ System.out.print(2); } } public class Dog extends Pet{ public Dog(){ System.out.print(4); } public Dog(String name){ this(); System.out.print(3); } } 执行new Dog(“棕熊”);后程序输出是哪项?()
第7题:
smith,SALES
null,SALES
smith,null
null,null
编译错误
第8题:
smith
null
SALES
编译错误
第9题:
new Inner(); // At line 3
new Inner(); // At line 8
new o.Inner(); // At line 8
new Outer.Inner(); // At line 8
第10题:
An instance of the Inner class can be constructed with “new Outer.Inner ()”
An instance of the inner class cannot be constructed outside of package foo.
An instance of the inner class can only be constructed from within the outer class.
From within the package bar, an instance of the inner class can be constructed with “new inner()”
第11题:
Compilation fails.
An instance of the Inner class can be constructed with “new Outer.Inner()”.
An instance of the Inner class cannot be constructed outside of package foo.
An instance of the Inner class can be constructed only from within the Outer class.
From within the package foo, and instance of the Inner class can be constructed with “new Inner()”.
第12题:
smith
null
SALES
编译错误
第13题:
1. public class Outer{ 2. public void someOuterMethod() { 3. // Line 3 4. } 5. public class Inner{} 6. public static void main( String[]argv ) { 7. Outer o = new Outer(); 8. // Line 8 9. } 10. } Which instantiates an instance of Inner?()
第14题:
Which declaration prevents creating a subclass of an outer class?()
第15题:
package foo; public class Outer ( public static class Inner ( ) ) Which statement is true? ()
第16题:
public class Pet{ private String name; public Pet(){ System.out.print(1); } public Pet(String name){ System.out.print(2); } } public class Dog extends Pet{ public Dog(String name){ //这里隐藏了一句代码:super.pet(); System.out.print(3); } } 执行new Dog(“棕熊”);后程序输出是哪项?()
第17题:
public class Plant { private String name; public Plant(String name) { this.name = name; } public String getName() { return name; } } public class Tree extends Plant { public void growFruit() { } public void dropLeaves() { } } Which is true?()
第18题:
143
423
243
1134
第19题:
33
13
23
123
第20题:
23
13
123
321
第21题:
smith
null
编译错误
name
第22题:
The code will compile without changes.
The code will compile if public Tree() { Plant(); } is added to the Tree class.
The code will compile if public Plant() { Tree(); } is added to the Plant class.
The code will compile if public Plant() { this(”fern”); } is added to the Plant class.
The code will compile if public Plant() { Plant(”fern”); } is added to the Plant class.
第23题:
smith,SALES
null,SALES
smith,null
null,null