public class flower {
private int petalCount = 0;
private String flowername = new String("null");
//定义花瓣数;
public flower(int i)
{
petalCount = i;
System.out.println("Constructed only by petal:" + petalCount);
}
//定义花的名称;
public flower(String name)
{
flowername = name;
System.out.println("Constructed only by name:" +flowername);
}
public flower(String name,int petal)
{
this(name);
this.petalCount=petal;
}
public flower()
{
this("Rose",27);
}
}
class flowerdemo
{
public static void main(String[] agrs)
{
flower f = new flower();
}
}
|
|