public class PhoneTest {
public static void main(String[] args) {
Phone phone = new Phone();
//使用成员变量
phone.brand = "小米6";
phone.print = 2499;
phone.color = "陶瓷黑";
System.out.println("买了一台" + phone.brand + ",价格" + phone.print + ",颜色"
+ phone.color);
//使用成员方法
phone.getCall("雷军");
phone.sendMessage(10086, "等会一起吃饭吧");
phone.playGame("雷军", 1.25, "一起玩LOL吧");
}
}
class Phone {
//品牌
String brand;
//价格
int print;
//颜色
String color;
//打电话的方法
public void getCall(String name) {
System.out.println("给" + name + "打电话");
}
//发短信的方法
public void sendMessage(int ms, String bean) {
System.out.println("给" + ms + "发短信,内容为:" + bean);
}
//玩游戏的方法
public void playGame(String name, double ms, String game) {
System.out.println("与" + name + "约定时间:" + ms + "号," + game);
}
}