WEB开发网
开发学院WEB开发Jsp java中this关键字用法 阅读

java中this关键字用法

 2009-11-12 20:59:36 来源:WEB开发网   
核心提示:view plaincopy to clipboardPRint?/** * this关键字用法 */public class Flower { int petalCount = 0; String s = "initial value"; Flower(int petals){ petalCo
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();  
  }  
}  

Tags:java this 关键字

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接