使用对象类型作为方法的参数——传的是地址
package cn.hu.day01.demo03;
public class Phone {
String brand;
double price;
String color;
public void call(String who){
System.out.println("给"+who+"打电话");
}
public void sendMessage(){
System.out.println("群发短信");
}
}
package cn.hu.day01.demo03;
public class Demo01PhoneParam {
public static void main(String[] args) {
Phone one=new Phone();
one.brand="苹果";
one.price=8388.0;
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.hu.day01.demo03;
public class Phone {
String brand;
double price;
String color;
public void call(String who){
System.out.println("给"+who+"打电话");
}
public void sendMessage(){
System.out.println("群发短信");
}
}
package cn.hu.day01.demo03;
public class Demo01PhoneReturn {
public static void main(String[] args) {
Phone two=getPhone();
System.out.println(two.price);
System.out.println(two.brand);
System.out.println(two.color);
}
public static Phone getPhone(){
Phone one=new Phone();
one.brand="苹果";
one.price=8388.0;
one.color="玫瑰金";
return one;
}
}