代码展示
package cn.ly.combinecode;
public class Demo04PhoneParam {
public static void main(String[] args) {
Phone one=new Phone();
one.brand="苹果";
one.price=9999.9;
one.color="玫瑰金";
method(one);
}
public static void method(Phone param){
System.out.println(param.brand);
System.out.println(param.price);
System.out.println(param.color);
}
}
结果
内存图解
使用对象类型作为方法的返回值类型
代码展示
package cn.ly.combinecode;
public class Demo05PhoneReturn {
public static void main(String[] args) {
Phone two=getPhone();
System.out.println(two.brand);
System.out.println(two.price);
System.out.println(two.color);
}
//使用对象类型作为方法的返回值类型
public static Phone getPhone(){
Phone one=new Phone();
one.brand="苹果";
one.price=9999.9;
one.color="玫瑰金";
return one;
}
}
效果
图解