首页 > 试题广场 >

阅读以下程序,写出输出结果。

[问答题]

阅读以下程序,写出输出结果。

public class Flower {
int petalCount = 0;
String s = "initial value";
 
Flower(int petals) {
petalCount = petals;
print("Constructor w/ int arg only, petalCount= " + petalCount);
}
 
Flower(String ss) {
print("Constructor w/ String arg only, s = " + ss);
s = ss;
}
 
Flower(String s, int petals) {
this(petals);
this.s = s; // Another use of "this"
print("String & int args");
}
 
Flower() {
this("hi", 47);
print("default constructor (no args)");
}
 
void printPetalCount() {
print("petalCount = " + petalCount + " s = " + s);
}
 
void print(String s) {
System.out.println(s);
}
 
public static void main(String[] args) {
Flower x = new Flower();
x.printPetalCount();
}
}

发表于 2017-08-25 20:42:34 回复(0)
Constructor w/ int arg only, petalCount= 47
String & int args
default constructor (no args)
petalCount = 47 s = hi


发表于 2017-05-17 16:18:11 回复(0)