码迷,mamicode.com
首页 > 其他好文 > 详细

使用对象作为方法返回值

时间:2019-12-15 21:48:05      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:对象   ros   color   font   class   ring   static   oid   mil   

package com.review;

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 P {
public static void main(String[] args) {
Phone phone = phone2();
System.out.println(phone.getPrice());
System.out.println(phone.getColor());
System.out.println(phone.getBrand());

}
public static Phone phone2() {
Phone one = new Phone();
one.setBrand("华为");
one.setColor("金色");
one.setPrice(8888);
return one;
}


}

使用对象作为方法返回值

标签:对象   ros   color   font   class   ring   static   oid   mil   

原文地址:https://www.cnblogs.com/xzwx668/p/12045986.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!