java中this关键字用法

王朝学院·作者佚名  2009-11-13  
宽屏版  字体: |||超大  

view plaincopy to clipboardprint?

/**

* this关键字用法

*/

public class Flower {

int petalCount = 0;

String s = "initial value";

Flower(int petals){

petalCount = petals;

System.out.println("Constructor with one int arg");

}

Flower(String ss){

System.out.println("Constructor with one string arg");

s = ss;

}

Flower(String ss, int petals){

this(petals);

this.s = ss;

System.out.println("Constructor with string and int args");

}

Flower(){

this("hi",47);

System.out.println("Default Constructor with no args");

}

void printPetalCount(){

System.out.println("petalCount = "+petalCount+"; s = "+s);

}

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

Flower x = new Flower();

x.printPetalCount();

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有