public class study {

private String s = new String("null");
  private int petalCount = 0;
 
  study(String ss) {
 
    System.out.println(
      "------------------------");
  }
  study(String s, int petals) {
      this(petals);
//!    this(s); // Can't call two!
    this.s = s; // Another use of "this"
    System.out.println("222222222222222222222---"+s);
  }
  study(int petals) {
    petalCount = petals;
    System.out.println(
      "1111111111111111111111---"
      + petalCount);
  }
study() {
    this("hi", 47);
    System.out.println(
      "333333333333333333333333");
  }

  void print() {
//!    this(11); // Not inside non-constructor!
    System.out.println(
      "petalCount = " + petalCount + " s = "+ s);
  }
 
   
  
public   static   void   main(String[]   args)     
  {  

study x = new study();
    x.print();
            }
为什么运行结果是:
1111111111111111111111---47
222222222222222222222---hi
333333333333333333333333
petalCount = 47 s = hi这个构造为什么没有执行:study(String ss)

解决方案 »

  1.   

    因为整个流程都没有调用study(String ss)
      

  2.   

    public static void main(String[] args)   
    {   study x = new study("输入构造参数,会执行");
    x.print();
      }
      

  3.   

    为什么没有调用?而却调用了study(int petals)
      

  4.   

    你的流程是:
    main(String[] args) 
    调用
    study()
    调用
    study(String s, int petals)
    调用
    study(int petals)
    结束
      

  5.   

    study(String s, int petals) {
    this(petals);
    //! this(s); // Can't call two!      这里被注释掉了this.s = s; // Another use of "this"
    System.out.println("222222222222222222222---"+s);
    }
      

  6.   

    我明白了,谢谢wutian4567268的回答。
      

  7.   

    你的流程是:
    main(String[] args) 
    调用
    study()
    调用
    study(String s, int petals)
    调用
    study(int petals)

    打印1111111111111111111111
    回到study(String s, int petals)
    打印222222222222222222222
    回到study()
    打印333333333333

    结束
      

  8.   

    没有调用这个构造方法,this("hi", 47)调用study(String s, int petals) 构造方法,this(petals)调用study(int petals)构造方法,没有调用到构造方法study(String ss)