/*手機類:成員變量:品牌brand ? 價格price?構(gòu)造方法:無參,帶兩個參成員方法:getXxx()/setXxx()show():輸出該類的所有成員變量值*/class Test705 { ????public static void main(String[] args) { ????????Phone p1 = new Phone(); ???????????????????????????????????? //使用空參 ????????p1.setBrand("蘋果"); ????????p1.setPrice(5288); ????????System.out.println(p1.getBrand() + p1.getPrice()); ????????Phone p2 = new Phone("小米",588); ?????????????????????//使用有參 ????????p2.show(); ????}}class Phone { ????private String brand; ????private int price; ????public Phone(){ ???????????????????????????????????????????? //空參 ????} ????public Phone(String brand,int pirce) { ???????? //有參 ????????this.brand = brand; ????????this.price = price; ????} ????public void setBrand(String brand) { ????????this.brand = brand; ????} ????public String getBrand() { ????????return brand; ????} ????public void setPrice(int price) { ?????????????????? ?//設(shè)置價格 ????????this.price = price; ????} ?????public int getPrice() { ???????????????????????????????? //獲取價格 ????????return price; ????} ????public void show() { ????????System.out.println(brand + ".." + price); ????}}
3 回答
已采納

Caballarii
TA貢獻(xiàn)1123條經(jīng)驗 獲得超629個贊
public Phone(String brand,int pirce) 有參構(gòu)造函數(shù)里price拼錯了
添加回答
舉報
0/150
提交
取消