类的继承day03

1.  下面代码的执行结果是什么?

public class Company {
        public static void main(String[] args) throws Exception {
            new Company().done();
        }
        void done() throws Exception{new GZDEPT5().mark();};
}


public class GZDEPT5 {
      void mark() throws Exception{System.out.println("GZDEPT5 的 mark() 方法");};
}


public class SDC  {
    void mark() throws Exception{System.out.println("SDC 的 mark() 方法");};
}

执行的结果是  GZDEPT5 的 mark() 方法

 

考察的知识点是  JAVA 中 子类强转为父类,实际上依然是子类,该引用只能调用父类中定义的方法和变量,,如果子类中重写了父类中的方法,,,那么在调用这个方法

的时候,,,,,将会调用子类中的这个方法。

posted @ 2018-10-18 21:59  雪落无痕1  阅读(104)  评论(0编辑  收藏  举报