package com.Summer_0426.cn; /** * @author Summer * 通过一个实例,验证方法重写输出的结果,子类优先调用子类拥有的被重写的方法 * */ public class Test01 { public static void main(String[] args) { JavaTeacher guoxiang = new JavaTeacher(); guoxiang.giveLesson();//输出结果,讲Java课 } } class Teacher{ String name; public void giveLesson() { System.out.println("讲数学课"); } } class JavaTeacher extends Teacher{ String tatoo; public void sing(){ System.out.println("唱歌"); } public void giveLesson() { System.out.println("讲Java课"); } }