public class C9 { String brand; double price; double size; public void call(){ System.out.println("品牌"+brand); System.out.println("价格"+price); System.out.println("尺寸"+size); } public void playGames(){ System.out.println("打游戏"); } @Override public String toString() { return "Phone{" + "brand='" + brand + '\'' + ", price=" + price + ", size=" + size + '}'; } }
import java.util.Arrays; import java.util.Arrays; public class C10 { public static void main(String[] args) { C9 p1 = new C9(); p1.brand="华为"; p1.price=4500; p1.size=6.1; p1.call(); p1.playGames(); System.out.println("**************"); C9 p2 = new C9(); p2.brand="苹果15ProMax"; p2.price=13000; p2.size=6.7; p2.call(); p2.playGames(); C9[] arr = {p1,p2}; System.out.println(Arrays.toString(arr)); } }