单选题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?()A  ne

题目
单选题
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?()
A

 new Inner(); // At line 3

B

 new Inner(); // At line 8

C

 new o.Inner(); // At line 8

D

 new Outer.Inner(); // At line 8

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

1. public interface A {  2. public void doSomething(String thing);  3. }  1. public class AImpl implements A {  2. public void doSomething(String msg) { }  3. }  1. public class B {  2. public A doit() {  3. // more code here  4. }  5.  6. public String execute() { 7. // more code here  8. }  9. }  1. public class C extends B {  2. public AImpl doit() {  3. // more code here  4. }  5.  6. public Object execute() {  7. // more code here  8. }  9. }  Which statement is true about the classes and interfaces in the exhibit?() 

  • A、 Compilation will succeed for all classes and interfaces.
  • B、 Compilation of class C will fail because of an error in line 2.
  • C、 Compilation of class C will fail because of an error in line 6.
  • D、 Compilation of class AImpl will fail because of an error in line 2.

正确答案:C

第2题:

package foo;  public class Outer {  public static class Inner {  }  }   Which statement is true?() 

  • A、 Compilation fails.
  • B、 An instance of the Inner class can be constructed with “new Outer.Inner()”.
  • C、 An instance of the Inner class cannot be constructed outside of package foo.
  • D、 An instance of the Inner class can be constructed only from within the Outer class.
  • E、 From within the package foo, and instance of the Inner class can be constructed with “new Inner()”.

正确答案:B

第3题:

以下程序的调试结果为?

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类实例的行出现编译错误


正确答案:D

第4题:

1. class Pizza {  2. java.util.ArrayList toppings;  3. public final void addTopping(String topping) {  4. toppings.add(topping); 5. }  6. }  7. public class PepperoniPizza extends Pizza {  8. public void addTopping(String topping) {  9. System.out.println(”Cannot add Toppings”);  10. }  11. public static void main(String[] args) {  12. Pizza pizza = new PepperoniPizza();  13. pizza.addTopping(”Mushrooms”);  14. }  15. }  What is the result?() 

  • A、 Compilation fails.
  • B、 Cannot add Toppings
  • C、 The code runs with no output.
  • D、 A NullPointerException is thrown in Line 4.

正确答案:A

第5题:

1. public class A {  2. void A() {  3. System.out.println(“Class A”);  4. }  5. public static void main(String[] args) {  6. new A();  7. }  8. }  What is the result?()  

  • A、 Class A
  • B、 Compilation fails.
  • C、 An exception is thrown at line 2.
  • D、 An exception is thrown at line 6.
  • E、 The code executes with no output.

正确答案:E

第6题:

1. public class a {  2. public void method1() {  3. try {  4. B b=new b();  5. b.method2();  6. // more code here  7. } catch (TestException te) {  8. throw new RuntimeException(te);  9. }  10. }  11. }  1. public class b {  2. public void method2() throws TestException {  3. // more code here  4. }  5. }  1. public class TestException extends Exception {  2. }  Given:  31. public void method() {  32. A a=new a();  33. a.method1();  34. }  Which is true if a TestException is thrown on line 3 of class b?()

  • A、 Line 33 must be called within a try block.
  • B、 The exception thrown by method1 in class a is not required to be caught.
  • C、 The method declared on line 31 must be declared to throw a RuntimeException.
  • D、 On line 5 of class a, the call to method2 of class b does not need to be placed in a try/catch block.

正确答案:B

第7题:

1. public class A {  2. public void doit() {  3. }  4. public String doit() {  5. return “a”;  6. }  7. public double doit(int x) {  8. return 1.0;  9. }  10.}  What is the result?() 

  • A、 An exception is thrown at runtime.
  • B、 Compilation fails because of an error in line 7.
  • C、 Compilation fails because of an error in line 4.
  • D、 Compilation succeeds and no runtime errors with class A occur.

正确答案:C

第8题:

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?()  

  • A、 new Inner(); // At line 3
  • B、 new Inner(); // At line 8
  • C、 new o.Inner(); // At line 8
  • D、 new Outer.Inner(); // At line 8

正确答案:A

第9题:

1. public class X {  2. public static void main (String[]args)   {  3. int [] a = new int [1]  4. modify(a);  5. System.out.printIn(a[0]);  6. }  7.    8. public static void modify (int[] a)  {  9.   a[0] ++;  10.    } 11. }       What is the result?()

  • A、 The program runs and prints “0”
  • B、 The program runs and prints “1”
  • C、 The program runs but aborts with an exception.
  • D、 An error “possible undefined variable” at line 4 causes compilation to fail.
  • E、 An error “possible undefined variable” at line 9 causes compilation to fail.

正确答案:B

第10题:

package foo; public class Outer (  public static class Inner (  )  )   Which statement is true? () 

  • A、 An instance of the Inner class can be constructed with “new Outer.Inner ()”
  • B、 An instance of the inner class cannot be constructed outside of package foo.
  • C、 An instance of the inner class can only be constructed from within the outer class.
  • D、 From within the package bar, an instance of the inner class can be constructed with “new inner()”

正确答案:A

更多相关问题