1. 创建 Phone 类
package class_object; public class Phone { String brand; String color; double price; void call(String who){ System.out.println("call "+who); } void sendMes(String message){ System.out.println("send "+message); } }
2. 创建使用 Phone 类 , 对象装载数据传递到方法中
package class_object; /** * 类 做为方法的参数 */ public class ClassParam { public static void main(String[] args) { Phone p = new Phone(); p.brand = "华为"; p.color = "red"; p.price = 4999; ts(p); } /** * 对象装载数据 */ public static void ts(Phone param) { System.out.println(param.brand); System.out.println(param.price); System.out.println(param.color); param.call("罗汉堂"); param.sendMes("有内鬼,中止交易"); } }