java 子类 父类

一、子类继承父类,子类重载父类的方法,不能改变返回类型。

class Super {
    public Integer getLenght() {
        return new Integer(4);
    }
}

public class Sub extends Super {
    public Long getLenght() {
        return new Long(5);
    }

    public static void main(String[] args) {
        Super sooper = new Super();
        Sub sub = new Sub();
        System.out.println(sooper.getLenght().toString() + ","
                + sub.getLenght().toString());
    }
}

输出是什么? E
A. 4,4
B. 4,5
C. 5,4
D. 5,5
E. 编译失败。

posted on 2013-10-17 22:06  wtggtw  阅读(174)  评论(0)    收藏  举报

导航