黑马程序员技术交流社区
标题:
手机类的创建与调用
[打印本页]
作者:
奋飞的小模糊
时间:
2016-3-12 00:13
标题:
手机类的创建与调用
class Demo {
public static void main(String[] args) {
Phone p = new Phone("三星",998);
p.show();
Phone p1 = new Phone();
p1.setBrand("华为");
p1.getBrand();
p1.setPrice(5678);
p1.getPrice();
p1.show();
}
}
class Phone {
private String brand;
private int price;
public Phone() {}
public Phone(String brand,int price ) {
this.brand = brand;
this.price = price;
}
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 show() {
System.out.println("手机的品牌是:"+brand+",价格是:"+price);
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2