class Demo_Phone { //创建一个测试类
public static void main(String[] args) { //main主方法
Phone b = new Phone("锤子",1999,"十核");
b.Function();
}
}
class Phone { //创建一个基本类
private String brand; //私有化并初始化成员变量
private int price;
private String cpu;
public Phone(String brand,int price,String cpu) { //创建有参构造方法
this.brand = brand;
this.price = price;
this.cpu = cpu;
}
public void setBrand(String brand) { //设置品牌
this.brand = brand;
}
public String getBrand() { //获取品牌
return brand;
}
public void setPrice(int price) { //设置价格
this.price = price;
}
public int getPrice() { //获取价格
return price;
}
public void setCpu(String cpu) { //设置手机配置
this.cpu = cpu;
}
public String getCpu() { //获取手机配置
return cpu;
}
public void Function() { //创建方法
System.out.println("品牌:"+brand+" "+"价格:"+price+" "+"CPU配置"+cpu); //输出手机品牌,价格,配置
}
}
|
|