使用对象作为参数

public class Phone {
private String color;
private int price;
private String brand;

public Phone() {
}

public Phone(String color, int price, String brand) {
this.color = color;
this.price = price;
this.brand = brand;
}

public String getColor() {
return color;
}

public void setColor(String color) {
this.color = color;
}

public int getPrice() {
return price;
}

public void setPrice(int price) {
this.price = price;
}

public String getBrand() {
return brand;
}

public void setBrand(String brand) {
this.brand = brand;
}
}
========================================
public class Phone1 {
public static void main(String[] args) {
Phone one=new Phone();
one.setBrand("华为");
one.setColor("金色");
one.setPrice(8888);
phone(one);
}
public static void phone(Phone phone1){
System.out.println(phone1.getBrand());
System.out.println(phone1.getColor());
System.out.println(phone1.getPrice());
}
}

猜你喜欢

转载自www.cnblogs.com/xzwx668/p/12045916.html
今日推荐