Java重载经典面试题

版权声明:转载请注明出处,谢谢! https://blog.csdn.net/qq_34872748/article/details/86501916
public class StaticDispatch {
	static abstract class Human{
		
	}
	static class Man extends Human{
		
	}
	static class Woman extends Human{
		
	}
	public void sayHello(Human guy) {
		System.out.println("hello , guy!");
	}
	public void sayHello(Man guy) {
		System.out.println("hello , gentle!");
	}
	public void sayHello(Woman guy) {
		System.out.println("hello , ladly!");
	}
	public static void main(String[] args) {
		Human man = new Man();
		Human woman = new Woman();
		StaticDispatch sr = new StaticDispatch();
		sr.sayHello(man);
		sr.sayHello(woman);
	}
}

这段代码摘抄自周大神的《深入理解Java虚拟机》一书中,能答上的小伙伴证明你对重载理解的非常透彻了。。。。。。。。

猜你喜欢

转载自blog.csdn.net/qq_34872748/article/details/86501916