继承的细节

class Father{
	String name;
	public Father(){
		name="father";
	}
	public String getName() {
		show();
		return name;
	}
	public void show() {
		System.out.println("father's show...");
	}
}
public class Son extends Father{
	public static void main(String[] args) {
		Father f=new Son();
		System.out.println(f.getName());
	}
	public void show() {
		System.out.println("son's show...");
	}
}

运行结果:

Son's show...
father

猜你喜欢

转载自blog.csdn.net/Sweeneyzuo/article/details/82191453