黑马程序员技术交流社区
标题:
面向对象第二天作业,写了一个手机类
[打印本页]
作者:
hxh362805079
时间:
2015-12-12 21:43
标题:
面向对象第二天作业,写了一个手机类
两种属性赋值方法 构造函数和SetXXX方法
class Demo3_Phone
{
public static void main(String[] args)
{
Phone p=new Phone();
p.setBrand("三星");
p.setPrice(1288);
System.out.println(p.getBrand()+"-----"+p.getPrice());
p.call();
p.sendMessage();
p.palyGame();
}
}
class Phone{
private String brand;
private int price;
public void call(){
System.out.println("打电话");
}
public void sendMessage(){
System.out.println("发短信");
}
public void palyGame(){
System.out.println("玩游戏");
}
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;
}
}
作者:
我有一个邮箱了
时间:
2015-12-12 23:14
楼主写的不错,顶一个
作者:
乐林荫
时间:
2015-12-13 11:51
写的不错,顶一个吧
作者:
乐林荫
时间:
2015-12-13 11:52
写的不错,顶一个吧
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2