定义手机类,手机有品牌(brand),价格(price)和颜色(color)三个属性,有打电话call()和sendmessage()两个功能。\n\n 请定义出手机类,类中要有空参、有参构造方
时间: 2023-04-28 09:04:56 浏览: 198
法,以及属性的get和set方法,同时实现打电话和发送短信的方法。代码如下:
```
public class Phone {
private String brand;
private double price;
private String color;
public Phone() {
}
public Phone(String brand, double price, String color) {
this.brand = brand;
this.price = price;
this.color = color;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public void call() {
System.out.println("打电话");
}
public void sendMessage() {
System.out.println("发送短信");
}
}
```
阅读全文