使用对象作为参数
Posted xzwx668
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用对象作为参数相关的知识,希望对你有一定的参考价值。
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());
}
}
以上是关于使用对象作为参数的主要内容,如果未能解决你的问题,请参考以下文章