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 ClassParamReturn { public static void main(String[] args) { ClassParamReturn cc = new ClassParamReturn(); Phone pp = cc.getPhone(); System.out.println(pp); System.out.println(pp.brand); System.out.println(pp.price); System.out.println(pp.color); } Phone getPhone(){ Phone p = new Phone(); p.brand = "小米"; p.price = 2999; p.color = "yellow"; return p; } }