日期:2014-05-20 浏览次数:20981 次
class Soap{
private String s;
Soap(){
System.out.println("Soap");
s = "Constructed";
}
public String toString(){
return s;
}
}
public class Chushihua {
private String s1 = "happy" ,
s2 = "happy" ,
s3,s4;
private Soap castille;
private int i;
private float toy;
public Chushihua(){
System.out.println("Inside bath");
s3 = "Joy";
toy = 3.14f;
castille = new Soap();
}
{
i = 47;
}
public String toString() {
if(s4 == null)
s4 = "Joy";
return
"s1 = " + s1 + "\n" +
"s2 = " + s2 + "\n" +
"s3 = " + s3 + "\n" +
"s4 = " + s1 + "\n" +
"i = " + i + "\n" +
"toy = " + toy + "\n" +
"castille = " + castille ;
}
public static void main(String args[]){
Chushihua b = new Chushihua();
System.out.println(b);
}
}
class Vehicle {
int passengers;
int fuelcap;
int mpg;
}
------解决方案--------------------
楼主看书不仔细。我现在也在看这本书。书中,明明很清楚的注释出了各种初始化方式出现的地方。你再去看下吧。。。