- public class Demo111 {
- public void method(Father f)
- {
- System.out.println("Father");
- }
- public void method(Son s)
- {
- System.out.println("Son");
- }
- public static void main(String[] args)
- {
- Demo111 aa=new Demo111();
- aa.method(new Father());
- aa.method(new Son());//去掉public void method(Son s)方法,便会输出Father,为什么?
- }
- }
- class Father
- {
- }
- class Son extends Father
- {
- }
复制代码 类Demo111中两个方法应该是重载了,这是编译时多态还是运行时多态? |
|