1. class A {  2. public int getNumber(int a) {  3.     return a + 1;  4. }  5. }  6.    7. class B extends A {  8. public int getNumber (int a) {  9. return a + 2  10. }  11.    12. public static void main (String args[])  {  13. A a = new B();  14. Syst

题目

1. class A {  2. public int getNumber(int a) {  3.     return a + 1;  4. }  5. }  6.    7. class B extends A {  8. public int getNumber (int a) {  9. return a + 2  10. }  11.    12. public static void main (String args[])  {  13. A a = new B();  14. System.out.printIn(a.getNumber(0));  15.    } 16. }     What is the result?()  

  • A、 Compilation succeeds and 1 is printed.
  • B、 Compilation succeeds and 2 is printed.
  • C、 An error at line 8 causes compilation to fail.
  • D、 An error at line 13 causes compilation to fail.
  • E、 An error at line 14 causes compilation to fail.

相似考题
更多“1. class A {  2. public int getNumber(int a) {  3.     return a + 1;  4. }  5. }  6.    7. class B extends A {  8. public int getNumber (int a) {  9. return a + 2  10. }  11.    12. public static void main (String args[])  {  13. A a = new B();  14. Syste”相关问题
  • 第1题:

    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

  • 第2题:

    1. public class SwitchTest {  2. public static void main (String []args)  {  3. System.out.PrintIn(“value =” +switchIt(4));  4. }  5. public static int switchIt(int x)  {  6. int j = 1;  7. switch (x) {  8. case 1: j++;  9. case 2: j++;  10. case 3: j++;  11. case 4: j++;  12. case 5: j++;  13. default:j++;  14. }  15. return j + x;  16. }  17. }     What is the output from line 3?()  

    • A、 Value = 3
    • B、 Value = 4
    • C、 Value = 5
    • D、 Value = 6
    • E、 Value = 7
    • F、 Value = 8

    正确答案:F

  • 第3题:

    10. interface Foo { int bar(); }  11. public class Sprite {  12. public int fubar( Foo foo) { return foo.bar(); }  13. public void testFoo() {  14. fubar(  15. // insert code here  16.);  17. }  18. }  Which code, inserted at line 15, allows the class Sprite to compile?() 

    • A、 Foo { public int bar() { return 1; } }
    • B、 new Foo { public int bar() { return 1; } }
    • C、 newFoo() { public int bar(){return 1; } }
    • D、 new class Foo { public int bar() { return 1; } }

    正确答案:C

  • 第4题:

    1. package foo;  2.    3. import java.util.Vector;  4.    5. private class MyVector extends Vector {  6. int i = 1;  7. public MyVector()  {  8. i = 2;  9.    }  10. }  11.    12. public class MyNewVector extends MyVector {  13. public MyNewVector ()  {  14. i = 4;  15. }  16. public static void main (String args [])  {  17. MyVector v = new MyNewVector();  18.   }  19. }     The file MyNewVector.java is shown in the exhibit.  What is the result?()  

    • A、 Compilation will succeed.
    • B、 Compilation will fail at line 5.
    • C、 Compilation will fail at line 6.
    • D、 Compilation will fail at line 14.
    • E、 Compilation will fail at line 17.

    正确答案:B

  • 第5题:

    现有:   1. class Synapse {    2.    protected int gap() { return 7; }    3. }   4.     5. class Creb extends Synapse {    6.   // insert code here   7. }    分别插入到第 6 行,哪三行可以编译?()

    • A、 int gap() { return 7; }
    • B、 public int gap() { return 7; }
    • C、 private int gap(int x) { return 7; }
    • D、 protected Creb gap() { return this; }
    • E、 public int gap() { return Integer.getInteger ("42"); }

    正确答案:B,C,E

  • 第6题:

    class A {  public byte getNumber() {  return 1;  }  }  class B extends A {  public short getNumber() {  return 2;  }  public static void main(String args[]) {  B b = new B();  System.out.println(b.getNumber()); }  }   What is the result?()

    • A、 1
    • B、 2
    • C、 An exception is thrown at runtime.
    • D、 Compilation fails because of an error in line 8.
    • E、 Compilation fails because of an error in line 14.

    正确答案:D

  • 第7题:

    1. class A {  2. public byte file Number ( ) { 3. return l;  4. }  5. }  6.  7. Class B extends A {  8. public short getNumber( ) {  9.  return 2;  10. }  11.  12. public short getNumber( ) {  13. B b = new B( );  14. System.out.printIn(b.getNumber( ));  15. }  16. }   What is the result()?  

    • A、 Compilation succeeds and l is printed.
    • B、 Compilation succeeds and 2 printed.
    • C、 An error at line 8 cause compilation to fail.
    • D、 An error at line 14 cause complication to fail.
    • E、 Complication succeeds but an exception is thrown at line 14.

    正确答案:C

  • 第8题:

    1. public class A {  2.  3. private int counter = 0;  4.  5. public static int getInstanceCount() {  6. return counter;  7. }  8.  9. public A() {  10. counter++;  11. }  12.  13. }  Given this code from Class B:  25.A a1 =new A();  26. A a2 =new A();  27. A a3 =new A();  28. System.out.printIn(A.getInstanceCount() ); What is the result?() 

    • A、 Compilation of class A fails.
    • B、 Line 28 prints the value 3 to System.out.
    • C、 Line 28 prints the value 1 to System.out.
    • D、 A runtime error occurs when line 25 executes.
    • E、 Compilation fails because of an error on line 28.

    正确答案:A

  • 第9题:

    1. public class A {  2. public String doit(int x, int y) {  3. return “a”;  4. }  5.  6. public String doit(int... vals) {  7. return “b”;  8. } 9. }  Given:  25. A a=new A();  26. System.out.println(a.doit(4, 5));  What is the result?() 

    • A、 Line 26 prints “a” to System.out.
    • B、 Line 26 prints „b” to System.out.
    • C、 An exception is thrown at line 26 at runtime.
    • D、 Compilation of class A will fail due to an error in line 6.

    正确答案:A

  • 第10题:

    单选题
    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.


    正确答案: D
    解析: 暂无解析

  • 第11题:

    单选题
    1. public class test (  2. public static void main(string args[]) {  3. int 1= 0;  4. while (i)  {  5. if (i==4) {  6. break;  7. }  8. ++i;  9. }  10.    11. }  12. )   What is the value of i at line 10?()
    A

     0

    B

     3

    C

     4

    D

     5

    E

     The code will not compile.


    正确答案: E
    解析: 暂无解析

  • 第12题:

    单选题
    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.


    正确答案: D
    解析: 暂无解析

  • 第13题:

    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

  • 第14题:

    1. class A {  2. public byte getNumber ()  {  3.   return 1;  4.   }  5. }  6.    7. class B extends A {  8. public short getNumber()  {  9.  return 2;  10. }  11.    12. public static void main (String args[]) {   13.    B  b = new B ();  14.      System.out.printIn(b.getNumber())     15.   }  16. }    What is the result?()  

    • A、 Compilation succeeds and 1 is printed.
    • B、 Compilation succeeds and 2 is printed.
    • C、 An error at line 8 causes compilation to fail.
    • D、 An error at line 14 causes compilation to fail.
    • E、 Compilation succeeds but an exception is thrown at line 14.

    正确答案:C

  • 第15题:

    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

  • 第16题:

    1. public class Test { 2. public static String output =””; 3.  4. public static void foo(int i) { 5. try { 6. if(i==1) { 7. throw new Exception(); 8. } 9. output += “1”; 10. } 11. catch(Exception e) { 12. output += “2”; 13. return; 14. } 15. finally { 16. output += “3”;17. } 18. output += “4”; 19. } 20.  21. public static void main(String args[]) { 22. foo(0); 23. foo(1); 24.  25. }26. } What is the value of the variable output at line 23?()


    正确答案:13423

  • 第17题:

    1. class A {  2. public String toString ()  {  3. return “4”;  4. }  5. }  6. class B extends A {  7. public String toString ()   {  8. return super.toString()  + “3”;  9. }  10. }  11. public class Test {  12.   public static void main(String[]args)  {  13.      System.out.printIn(new B());  14.      }  15. }    What is the result?()  

    • A、 Compilation succeeds and 4 is printed.
    • B、 Compilation succeeds and 43 is printed.
    • C、 An error on line 9 causes compilation to fail.
    • D、 An error on line 14 causes compilation to fail.
    • E、 Compilation succeeds but an exception is thrown at line 9.

    正确答案:B

  • 第18题:

    1. class A {  3. public String to String() {  4. return “4”;  5. }  6. }  7. class B extends A {  8. public String toString() { 9. return super.toString() + “3”;  10. }  11. }  12. public class Test {  13. public static void main (String[] args) {  14. System.out.printIn(new B()); 15. }  16. }   What is the result( )?  

    • A、 Compilation succeeds and 4 is printed.
    • B、 Compilation …………… is printed.
    • C、 An error on line 9 cause compilation to fail.
    • D、 An error on line 14 cause compilation to fail.
    • E、 Compilation succeeds but an exception is thrown at line 9.

    正确答案:B

  • 第19题:

    1. public class test (  2. public static void main(string args[]) {  3. int 1= 0;  4. while (i)  {  5. if (i==4) {  6. break;  7. }  8. ++i;  9. }  10.    11. }  12. )   What is the value of i at line 10?()

    • A、 0
    • B、 3
    • C、 4
    • D、 5
    • E、 The code will not compile.

    正确答案:E

  • 第20题:

    class A {   public int getNumber(int a) {   return a + 1;   }   }    class B extends A {   public int getNumber (int a) {   return a + 2   }    public static void main (String args) {   A a = new B();   System.out.printIn(a.getNumber(0));   }   }   What is the result? () 

    • A、 Compilation succeeds and 1 is printed.
    • B、 Compilation succeeds and 2 is printed.
    • C、 An error at line 8 causes compilation to fail.
    • D、 An error at line 13 causes compilation to fail.
    • E、 An error at line 14 causes compilation to fail.

    正确答案:B

  • 第21题:

    单选题
    class A {  public byte getNumber() {  return 1;  }  }  class B extends A {  public short getNumber() {  return 2;  }  public static void main(String args[]) {  B b = new B();  System.out.println(b.getNumber()); }  }   What is the result?()
    A

     1

    B

     2

    C

     An exception is thrown at runtime.

    D

     Compilation fails because of an error in line 8.

    E

     Compilation fails because of an error in line 14.


    正确答案: D
    解析: getNumber() in B cannot override getNumber() in A; attempting to use incompatible return type: short to byte. 

  • 第22题:

    单选题
    1. public class A {  2. public String doit(int x, int y) {  3. return “a”;  4. }  5.  6. public String doit(int... vals) {  7. return “b”;  8. } 9. }  Given:  25. A a=new A();  26. System.out.println(a.doit(4, 5));  What is the result?()
    A

     Line 26 prints “a” to System.out.

    B

     Line 26 prints „b” to System.out.

    C

     An exception is thrown at line 26 at runtime.

    D

     Compilation of class A will fail due to an error in line 6.


    正确答案: C
    解析: 暂无解析

  • 第23题:

    多选题
    1. class Super {  2. private int a;  3. protected Super(int a) { this.a = a; }  4. }  .....  11. class Sub extends Super {  12. public Sub(int a) { super(a); }  13. public Sub() { this.a= 5; }  14. }  Which two, independently, will allow Sub to compile?()
    A

    Change line 2 to: public int a;

    B

    Change line 2 to: protected int a;

    C

    Change line 13 to: public Sub() { this(5); }

    D

    Change line 13 to: public Sub() { super(5); }

    E

    Change line 13 to: public Sub() { super(a); }


    正确答案: C,B
    解析: 暂无解析