public 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 call() {
System.out.println("打电话");
}
public void sendMessage() {
System.out.println("发短信");
}
public void playGame() {
System.out.println("玩游戏");
}
}

281496929 发表于 2017-3-6 23:25
你的String brand int price 是私有的,所以需要set get 为他提供方法 便于外部访问,打电话,发短信的功 ...
281496929 发表于 2017-3-6 23:28
既然有构造函数了就没有那个空参的构造函数了吧
281496929 发表于 2017-3-6 23:26
我也是新手,回答的不好,
yangjs 发表于 2017-3-6 23:22
肯定比上基础班难些,主要是没老师给你讲解。



| 欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |