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. 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.

相关考题:

class A{public int getNumber(int a){return a+1;}}class B extends A{public int getNumber(int a, char c){return a+2;}public static void main(String[] args){B b=new B();System.out.println(b.getNumber(0));}}what is the result?()A.compilation succeeds and 1 is printedB.compilation succeeds and 2 is printedC.compilation succeeds and 3 is printedD.An error at this program cause compilation to fail

下面程序的输出结果是什么? class C1{ static int j=0; public void method(int a){ j++; } } class Test extends C1{ public int method(){ return j++; } public void result(){ method(j); System.out.println(j+method()); } public static void main(String args[]){ new TeA.0B.1C.2D.3

1. public class SimpleCalc {  2. public int value;  3. public void calculate() { value += 7; }  4. } And:  1. public class MultiCalc extends SimpleCalc {  2. public void calculate() { value -= 3; }  3. public void calculate(int multiplier) {  4. calculate();  5. super.calculate();  6. value *=multiplier;  7. }  8. public static void main(String[] args) {  9. MultiCalc calculator = new MultiCalc();  10. calculator.calculate(2);  11. System.out.println(”Value is: “+ calculator.value);  12. }  13. }  What is the result?() A、 Value is: 8B、 Compilation fails.C、 Value is: 12D、 Value is: -12E、 The code runs with no output.F、 An exception is thrown at runtime.

1. public class Target {  2. private int i = 0;  3. public int addOne() {  4. return ++i;  5. }  6. }  And:  1. public class Client {  2. public static void main(String[] args) {  3. System.out.println(new Target().addOne());  4. }  5. }  Which change can you make to Target without affecting Client?() A、 Line 4 of class Target can be changed to return i++;B、 Line 2 of class Target can be changed to private int i = 1;C、 Line 3 of class Target can be changed to private int addOne() {D、 Line 2 of class Target can be changed to private Integer i = 0;

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.

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.

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 = 3B、 Value = 4C、 Value = 5D、 Value = 6E、 Value = 7F、 Value = 8

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.

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; } }

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 ToppingsC、 The code runs with no output.D、 A NullPointerException is thrown in Line 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.

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

现有:   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"); }

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.

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、 1B、 2C、 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.

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.

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.

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、 0B、 3C、 4D、 5E、 The code will not compile.

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.

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.

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.

单选题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 1B 2C 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.

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

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

单选题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 0B 3C 4D 5E The code will not compile.

多选题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?()AChange line 2 to: public int a;BChange line 2 to: protected int a;CChange line 13 to: public Sub() { this(5); }DChange line 13 to: public Sub() { super(5); }EChange line 13 to: public Sub() { super(a); }

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