class A{ private int a=0; public A(){ } public A(int a){ //this(參數),不能本身的方法中調用本身的構造方法(程序棧溢出),只能調用一次,一個構造函數且使用第一行 this(); //this(); //驗證this.變量是調用成員變量,變量是調用局部變量。 this.a=a+1; System.out.println("局部變量"+a); System.out.println("成員變量"+this.a); } }
其餘優秀博客銜接 http://blog.csdn.net/fzfengzhi/article/details/2174406java
另外,構造函數爲何不能使用this,super不能在一個方法屢次地調用構造函數。以及只能在構造方法中調用構造方法函數