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

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


参考解析

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

相关考题:

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

Given: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.new Foo() { public int bar() { return 1; }D.new class Foo { public int bar() { return 1; }

下面程序的输出结果是【】。include using namespace std; class base { protected: int 下面程序的输出结果是【 】。include <iostream>using namespace std;class base{protected:int a;public:base(){cout<<"0":}};class basel: virtual public base{public:base1(){ cout<<"1";}};class base2 : virtual public base{public:base2(){cout<<"2";}};class derived : public base1,public base2{public:derived () {cout<<"3"; }}int main (){derived obj;cout<<end1;return 0;}

若有以下程序: include using namespace std; class Base { public:void who(){ cout 若有以下程序:include <iostream>using namespace std;class Base{public:void who(){cout<<"class Base"<<end1;}};class Derivedl : public Base{public:void who(){cout<<"class Derivedl"<<end1;}};class Derived2 : public Base{public:void who(){cout<<"class Derived2"<<end1;}};int main(){Base *p;Derivedl obj1;Derived2 obi2;p=obj 1;p=obj2;p->who ( );return 0;}则该程序运行后的输出结果是【 】。

若有以下程序:include using namespace std;class A{protected: int a;public: A() { 若有以下程序: #include <iostream> using namespace std; class A { protected: int a; public: A() { a=10; } }; class A1 : public A { public: A1() { a=a+1; } }; class A2 : public A { public: A2 () { a=a+2; } }; class B : public A1,public A2 { public: B(){} void print() { cout<<a<<end1; } }; int main ( ) { B obj; obj.print(); return 0; } 程序运行后的输出结果是( )。A.产生语法错误B.11C.12D.10

有如下程序: include class x { protected: int a; public:x(){ a=1;} }; class x 有如下程序: #include <iostream.h> class x { protected: int a; public: x() { a=1; } }; class x1 : virtual public x { public: x1() { a+=1; cout<<a; } }; class x2 : virtual public x { public: x2() { a+=2; cout<<a; } }; class y : public xl,public x2 { public: y() { cout<<a<<end1; } }; int main() { y obj; return O; } 该程序运行后的输出结果是( )。A.1B.123C.242D.244

class A {  protected int method1(int a, int b) { return 0; }  }  Which two are valid in a class that extends class A?() A、 public int method1(int a, int b) { return 0; }B、 private int method1(int a, int b) { return 0; }C、 private int method1(int a, long b) { return 0; }D、 public short method1(int a, int b) { return 0: }E、 static protected int method1(int a, int b) { return 0; }

1. public class ReturnIt {  2. return Type methodA(byte x, double y) {  3. return (long)x / y * 2;  4. }  5. }  What is the narrowest valid returnType for methodA in line2?()  A、 intB、 byteC、 longD、 shortE、 floatF、 double

public class X {  public X aMethod() { return this;}  }  public class Y extends X {  }  Which two methods can be added to the definition of class Y?()A、 public void aMethod() {}B、 private void aMethod() {}C、 public void aMethod(String s) {}D、 private Y aMethod() { return null; }E、 public X aMethod() { return new Y(); }

public class OuterClass {  private double d1  1.0;  //insert code here   }   You need to insert an inner class declaration at line2. Which two inner class declarations are valid?() A、 static class InnerOne {  public double methoda() {return d1;}  }B、 static class InnerOne {  static double methoda() {return d1;} }C、 private class InnerOne {  public double methoda() {return d1;} }D、 protected class InnerOne {  static double methoda() {return d1;} }E、 public abstract class InnerOne {  public abstract double methoda();  }

class One {   public One foo() { return this; }  }  class Two extends One {  public One foo() { return this; }  }  class Three extends Two {   // insert method here  }  Which two methods, inserted individually, correctly complete the Three class?()A、 public void foo() { }B、 public int foo() { return 3; }C、 public Two foo() { return this; }D、 public One foo() { return this; }E、 public Object foo() { return this; }

1. public class returnIt (  2. returnType methodA(byte x, double y) (  3. return (short) x/y * 2;  4. )  5. )   What is the valid returnType for methodA in line 2?()  A、 IntB、 ByteC、 LongD、 ShortE、 FloatF、 Double

1. public class OuterClass {  2. private double d1 = 1.0;  3. // insert code here  4. }  Which two are valid if inserted at line 3?()  A、 static class InnerOne { public double methoda() { return d1; } }B、 static class InnerOne { static double methoda() { return d1; } }C、 private class InnerOne { public double methoda() { return d1; } }D、 protected class InnerOne { static double methoda() { return d1; } }E、 public abstract class InnerOne { public abstract double methoda(); }

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.

public class returnIt (    returnType methodA(byte x, double y) (   return (short) x/y * 2;   )  )   What is the valid returnType for methodA in line 2?()A、 IntB、 ByteC、 LongD、 ShortE、 FloatF、 Double

单选题public class returnIt (    returnType methodA(byte x, double y) (   return (short) x/y * 2;   )  )   What is the valid returnType for methodA in line 2?()A IntB ByteC LongD ShortE FloatF Double

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

单选题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.printIn(b.getNumber())  }   }   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.

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

多选题public class X {  public X aMethod() { return this;}  }  public class Y extends X {  }  Which two methods can be added to the definition of class Y?()Apublic void aMethod() {}Bprivate void aMethod() {}Cpublic void aMethod(String s) {}Dprivate Y aMethod() { return null; }Epublic X aMethod() { return new Y(); }

单选题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. 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. public class OuterClass {  2. private double d1 = 1.0;  3. // insert code here  4. }  Which two are valid if inserted at line 3?()Astatic class InnerOne { public double methoda() { return d1; } }Bstatic class InnerOne { static double methoda() { return d1; } }Cprivate class InnerOne { public double methoda() { return d1; } }Dprotected class InnerOne { static double methoda() { return d1; } }Epublic abstract class InnerOne { public abstract double methoda(); }

多选题public class OuterClass {   private double d1 1.0;   //insert code here   }   You need to insert an inner class declaration at line2. Which two inner class declarations are valid?()Astatic class InnerOne {  public double methoda() {return d1;}  }Bstatic class InnerOne {  static double methoda() {return d1;}  }Cprivate class InnerOne {  public double methoda() {return d1;}  }Dprotected class InnerOne {  static double methoda() {return d1;}  }Epublic abstract class InnerOne {  public abstract double methoda();  }

单选题1. public class ReturnIt {  2. return Type methodA(byte x, double y) {  3. return (long)x / y * 2;  4. }  5. }  What is the narrowest valid returnType for methodA in line2?()A intB byteC longD shortE floatF double

多选题class One {   public One foo() { return this; }  }  class Two extends One {  public One foo() { return this; }  }  class Three extends Two {   // insert method here  }  Which two methods, inserted individually, correctly complete the Three class?()Apublic void foo() { }Bpublic int foo() { return 3; }Cpublic Two foo() { return this; }Dpublic One foo() { return this; }Epublic Object foo() { return this; }