flower.java

来自「这是我学习JAVA时自己的写的代码」· Java 代码 · 共 33 行

JAVA
33
字号
//: Flower.java
// Calling constructors with "this"
public class Flower {
private int petalCount = 0;
private String s = "unll";
Flower(int petals) {
petalCount = petals;
System.out.println("Constructor w/ int arg only, petalCount= "+ petalCount);
}
Flower(String ss) {
System.out.println("Constructor w/ String arg only, s=" + ss);
s = ss;
}
Flower(String s, int petals) {
this(petals);
//! this(s); // Can't call two!
this.s = s; // Another use of "this"
System.out.println("String & int args");
}
Flower() {
this("hi", 47);
System.out.println(
"default constructor (no args)");
}
void print() {
//! this(11); // Not inside non-constructor!
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 + =
减小字号Ctrl + -
显示快捷键?