package com.lianxi; public class FuLei { public FuLei() { System.out.println("父类构造方法"); } public void KaiChe() { System.out.println("爸爸会开车"); } public void YouXi() { System.out.println("爸爸会打游戏"); } }
package com.lianxi; public class ZiLei extends FuLei { public ZiLei() { System.out.println("子类构造方法"); } //重写 public void YouXi() { System.out.println("女儿会吃手"); } }
package com.lianxi; public class testJ { public static void main(String[] args) { // TODO 自动生成的方法存根 ZiLei nver = new ZiLei(); nver.KaiChe(); nver.YouXi(); System.out.println(); FuLei aa = new ZiLei(); aa.KaiChe(); aa.YouXi(); //调用子类的方法 } }