猿问

请大神帮我看看为什么价格输出是0

/*

手机类:

成员变量:

品牌brand   价格price 

构造方法:

无参,带两个参

成员方法:

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) {                     //设置价格

        this.price = price;

    }

     public int getPrice() {                                  //获取价格

        return price;

    }

    public void show() {

        System.out.println(brand + ".." + price);

    }

}


慕粉_LS
浏览 1558回答 3
3回答

Caballarii

public Phone(String brand,int pirce) 有参构造函数里price拼错了

happyJared

price跟pirce不一样 仔细点

慕粉_LS

小米的输出价格是 0.     为什么没输出588  问题在哪里.  请回答一下.
随时随地看视频慕课网APP

相关分类

Java
我要回答