//练习
class PhoneTest {
public static void main(String[] args) { //主方法
Phone1 p = new Phone1(); //定义一个Phone1类对象
p.setBrands("中兴");
p.setPrice(8);
System.out.println(p.getBrands()+"手机价钱是"+p.getPrice()+"元");
}
}
class Phone1 { //Phone1类
private String brands ;
private int price;
//set ,get 方法的定义
public void setBrands(String brands){
this.brands = brands;
}
public String getBrands() {
return brands;
}
public void setPrice(int price){
this.price = price;
}
public int getPrice() {
return price;
}
}
|
|