package duixiang;
class Car
{
private String tapy;
private String color;
private int number;
Car()//构造代码块
{
System.out.println("Benze!!!");
}
public void setTapy(String tapy)//暴露的设值接口
{
this.tapy=tapy;
}
public String getTapy()//暴露的传值接口
{
return tapy;
}
Car(String tapy )//构造函数
{
this.tapy=tapy;
show();
}
Car(String tapy,String color)
{
this.tapy=tapy;
this.color=color;
show();
}
Car(String tapy,String color,int number)
{
this(tapy);//this语句
this.tapy=tapy;
this.color=color;
this.number=number;
show();
}
void show()
{
System.out.println(tapy+"..."+color+"..."+number);
}
}
public class CarDemo
{
public static void main(String [] args)
{
Car c=new Car("a1");
Car c1=new Car("a2","blue");
Car c2=new Car("a3","yellow",5);
c.setTapy("a5");
System.out.println(c.getTapy());
}
}
对象(CarDemo)
最新推荐文章于 2022-06-03 21:15:51 发布