美文网首页
Java中构造器、成员函数调用继承、重写方法的区别

Java中构造器、成员函数调用继承、重写方法的区别

作者: bitlogo | 来源:发表于2016-11-18 09:44 被阅读0次
public class Father {
    public Father(){
        ss();
        System.out.println("Father's Con End!");
    }
    public void s(){
        System.out.println("This is Father's S!");
    }
    public void ss(){
        System.out.println("This is Father's SS!");
        s();
    }
}
public class Child extends Father{
    public void s(){
        System.out.println("This is Child's S!");
    }
    public void ss(){
        System.out.println("This is Child's SS!");
        super.ss();
    }
}
public class Test {
    public static void main(String[] args) throws UnsupportedEncodingException {
        Child child = new Child();
        child.ss();
    }
}

运行Test的输出为:

This is Father's SS!
This is Child's S!
Father's Con End!
This is Child's SS!
This is Father's SS!
This is Child's S!

相关文章

网友评论

      本文标题:Java中构造器、成员函数调用继承、重写方法的区别

      本文链接:https://www.haomeiwen.com/subject/edmjpttx.html