JAVA代码运行结果如下
作者:互联网
代码如下:
public class MobilPhone {
public String brand;
public MobilPhone(){
this.brand="诺基亚";
}
public MobilPhone(String bra){
this.brand=bra;
}
public String buy(){
return "没发工资, 买一个"+brand+"牌子的手机吧";
}
public String Buy(String reason){
return reason + ",快买一个" + brand + "牌子的手机吧!";
}
}
public class MobilPhoneTest {
public static void main(String[] args){
MobilPhone mp = new MobilPhone();
mp.brand="苹果"; //发工资了,修改品牌属性
String detail=mp.Buy("发工资啦"); //发工资了,调用带参构造方法
System.out.println(detail);
}
}
标签:JAVA,String,MobilPhone,brand,如下,代码运行,mp,public,发工资 来源: https://blog.csdn.net/nbqie66/article/details/115716599