java方法覆写
父方法如果是私有属性(private)就不能再子方法中重写
public class ExtendTest { public static void main(String[] args) {//主方法 new Child().prt(); } } class Child extends Father { public void printF() { System.out.println( "F-Child" ); } public void printM() { System.out.println( "M-Child" ); } } class Father { public void printF() { System.out.println( "public:Father" ); } private void printM() { System.out.println( "private:Mother" ); } public void prt() { printF(); printM(); } } |
输出:
F-Child
private:Mother
落霞与孤鹜齐飞,秋水共长天一色。