在主函数public static void main(String[] args) 里只吊用了不带参数的构造函数Flower(),
当一类中有多个构造函数时,对象的构造只匹配其对应类型的构造函数。
若写为 Flower x = new Flower( “***” ) 就会执行你想显示的结果了

解决方案 »

  1.   

    请问一下!
    为何可以显示
    Flower(int petals) 

      petalCount = petals; 
      System.out.println("Construtor w/ int arg only , petalCount = " + petals); 
    } 的结果哪!
    这个也是带类型的构造函数哪!
      

  2.   

    Flower x = new Flower(); //Flower() 
    this("hi",47);           //Flower(String s , int petals) 
    this(petals);            //Flower(int petals)
      

  3.   

    我的意思是:
     Flower(String ss) 

      System.out.println("Construtor w/ String arg only , s= " + ss); 
      s = ss; 
    }的结果不能显示!Flower(int petals) 

      petalCount = petals; 
      System.out.println("Construtor w/ int arg only , petalCount = " + petals); 
    } 的结果能显示!两个都是带型参的构造函数,为什么会出现不同的结果?
      

  4.   

    在main 函数里面的
    Flower x = new Flower(); 
    首先调用Flower();
    就是这个
    Flower() 

     this("hi",47); 
     System.out.println("default constructor (no args)"); 

    然后this("hi",47); 
    会调用
    Flower(String s , int petals) 

    this(petals); 
    this.s = s; 
    System.out.println("string & int args"); 
    } this(petals)会调用下面的构造方法
    Flower(int petals) 

      petalCount = petals; 
      System.out.println("Construtor w/ int arg only , petalCount = " + petals); 
    } 所以只有
     Flower(String ss) 

      System.out.println("Construtor w/ String arg only , s= " + ss); 
      s = ss; 
    传递字符串的没有被调用。
      

  5.   

    基本上是懂了!谢谢.请问一下:
    this.s = s;这句不是调用Flower(String ss) 吗?
    谢谢!!!!!
      

  6.   

    halfsea(傲视三界)答的不错.this.s = s是给类变量s赋值.s="hi"