public class phone {
public static void main(String[] args) {
iphone p=new iphone();
p.setBrand("sanxing");
p.setPrice(9123);
System.out.println(p.getBrand()+p.getPrice());
p.call();
p.send();
p.play();
}
}
class iphone { //java bean实体类,对别的类提供方法
private String brand; //品牌
private int price; //价格
public void setBrand(String brand) {
this.brand=brand;
}
public String getBrand(){
return this.brand;//this可省略
}
public void setPrice(int price){
this.price=price;
}
public int getPrice(){
return price;
}
public void call(){
System.out.println("dadianhua");
}
public void send(){
System.out.println("faduanxin");
}
public void play(){
System.out.println("wnayouxi");
}
代码结果