谁知道这个程序的运行结果 和原因 谢谢了~~~~ 
class testA { 
   public testA(){ 
    a1(); 
  } 
   public void a1() { 
     System.out.println("A-a1"); 
   } 
    
 } 
  
 public class testB extends testA{ 
   int bb=0; 
   public testB() { 
    bb=1000; 
   } 
   public void a1() { 
    System.out.println("bb is"+bb); 
     System.out.println("B-a1"); 
   } 
   public static void main(String[] args) { 
     new testB(); 
   } 
  
 } 

解决方案 »

  1.   

    先new testA ().
    而testA ()中又调用了a1();
    所以结果是:
    bb is0
    B-a1
      

  2.   


    可是testA ()中又调用了a1();为什么不调用testA中的A1?
      

  3.   

    在new子类时先调用父类的构造函数,所以先执行a1()方法。由于子类重写了a1()方法,执行System.out.println("bb is"+bb); 此时b=0.最后才是给b赋值1000.
    所以结果应该是:bb is0
    B-a1
    不知道对不对
      

  4.   

    我如果把int bb=0; 改成bb=别的数 
    会对结果影响吗????
      

  5.   

    现在新问题是 
    我如果把int bb=0; 改成bb=别的数 
    会对结果影响吗???? 
      

  6.   

    不能做任何输出嘛
    因为在
    public testB() { 
        bb=1000; 
      } 
    构造函数里面没有运用父类的构造函数
    若:
    public testB() { 
        bb=1000; 
    super();
      } 这样才有可能存在输出
      

  7.   

    bb is0
    B-a1
    结果是一样的。bb的值改要6,但在调用构造函数前,bb是没有进入到int bb=6,bb只能使用它的默认值,而int的默认值为0,所以结果永远是一样的。
      

  8.   

    对啊,不能这样写,Super()的调用必须是构造函数中的第一句