可学答题网 > 问答 > SCJP程序员认证考试题库
目录: 标题| 题干| 答案| 搜索| 相关
问题

class A {  public&ensp


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. 

分类:SCJP程序员认证考试题库