java 子类对象调用父类方法吗

如题所述

能,看如下代码

class A { //父类
 public void show () {
  System.out.println("This is father Method show !");
 }
 public void test () {
  System.out.println("This is father Method test !");
 }
}
class B extends A {//子类
 @Override
 public void show() {
  System.err.println("This is son Method show !");
 }
}

//测试方法
public static void main(String[] args) throws Exception {
  A a = new B();
  a.show();
  a.test();
 }   

//输出信息
This is father Method test !
This is son Method show !

子类重写了父类的show方法(拓展)

父类的test方法使用子类的实例对象也能调用,不过这个和父类test的权限有关系。

温馨提示:答案为网友推荐,仅供参考
相似回答