A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

潘弘非

初级黑马

  • 黑马币:10

  • 帖子:3

  • 精华:0

© 潘弘非 初级黑马   /  2020-3-2 19:03  /  1234 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

package com.itheima.test;

public class zuoye1 {
    public static void main(String[] args) {
        Phone P = new Phone("华为",2800);
        P.setBrand("华为");
        P.setPrice(2800);
        P.call();
        P.sendMessage();
        P.playGame();

    }
}
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("正在使用价格为" + price + "元的" + brand + "品牌的手机打电话...");
        }

        public void sendMessage() {
            System.out.println("正在使用价格为" + price + "元的" + brand + "品牌的手机发信息...");
        }

        public void playGame() {
            System.out.println("正在使用价格为" + price + "元的" + brand + "品牌的手机玩游戏...");
        }
    }

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马