⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flower.java

📁 俄罗斯方块游戏java
💻 JAVA
字号:
//: Flower.java
public class Flower {
  private int petalCount = 0;
  private String s = new String("null");	//复杂类型必须初始化
  Flower(int petals) {		//仅带有(int)的初始化函数
    petalCount = petals;
    System.out.println( "Constructor w/ int arg only, petalCount= "
      + petalCount);
  }
  Flower(String ss) {		//仅带有(String)的初始化函数
    System.out.println( "Constructor w/ String arg only, s=" + ss);
    s = ss;
  }
  Flower(String s, int petals) {	//带有(String,int)的初始化函数
    this(petals);
//!    this(s); 	//尽管可用this调用一个构建器,但不可调用两个
    this.s = s; 		// 另外的一种this的使用方法
    System.out.println("String & int args");
  }
  Flower() {		//无参数的初始化函数
    this("hi", 47);	//用this调用带有(String,int)的初始化函数
    System.out.println( "default constructor (no args)");
  }
  void print() {
//!    this(11); 		// 没有如此的构造函数。
    System.out.println(
      "petalCount = " + petalCount + " s = "+ s);
  }
  public static void main(String[] args) {		//程序入口
    Flower x = new Flower();		//构造公共类
    x.print();			//用对象调用函数
  }
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -