public class Car{
String type; //属性1,类型
String colour; //属性2,颜色
String id; // 属性3,车牌号
int maxspeed; //属性4,最高时速
//构造方法1 ----无参数的构造方法
public Car(){}
//构造方法2 ----有参数的构造方法
public Car(String type,String colour,String id,int maxspeed){
this.type=type;
this.colour=colour;
this.id=id;
this.maxspeed=maxspeed;
}
//构造方法3----可以由外部进行修改
String getType(){
return type;
}
String getColour(){
return colour;
}
String getId(){
return id;
}
int getMaxspeed(){
return maxspeed;
}
void setType(String type){
this.type=type;
}
void setColour(String colour){
this.colour=colour;
}
void setId(String id){
this.id=id;
}
void maxspeed(int maxspeed){
this.maxspeed=maxspeed;
}
String carInFo(){
return "这辆车的名字是:"+type+",\n它的颜色超级的独特是"+colour+"色的,\n它的车牌号是:"+id+"\n最高时速 为:"+maxspeed+"km/h\n";
}
public static void main(String[] args){
Car car1=new Car();
car1.type="奔驰G";
car1.colour="red";
car1.id="陕A 00000";
car1.maxspeed=150;
System.out.println(car1.carInFo());
Car car2=new Car("比亚迪","yellow","陕A 12345",180);
System.out.println(car2.carInFo());
}
}