黑马程序员技术交流社区

标题: 问下面的题目的输出结果 [打印本页]

作者: jk7130866    时间: 2015-7-21 21:28
标题: 问下面的题目的输出结果
本帖最后由 jk7130866 于 2015-7-21 21:38 编辑

(一)相关类class A{               public String show(D obj)
                           {   
                           return ("A and D");   
                            }            
                   public String show(A obj){         
                          return ("A and A");      
                             }  

  }  
class B extends A{         
               public String show(B obj)
                          {            
                 return ("B and B");        
                         }        
            public String show(A obj){           
                       return ("B and A");      
                   }   
        }  
class C extends B{}   
class D extends B{}
二)问题:以下输出结果是什么


       A a1 = new A();      
     A a2 = new B();      
     B b = new B();      
     C c = new C();        
    D d = new D();         
System.out.println(a1.show(b));   ①   
     System.out.println(a1.show(c));   ②      
    System.out.println(a1.show(d));   ③      
   System.out.println(a2.show(b));   ④        
  System.out.println(a2.show(c));   ⑤      
   System.out.println(a2.show(d));   ⑥        
  System.out.println(b.show(b));    ⑦      
   System.out.println(b.show(c));    ⑧      
    System.out.println(b.show(d));    ⑨   










欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2