import java.sql.SQLOutput; public class Phone { String brand; double price; double size; public void shuxin(){ System.out.println("品牌:"+brand); System.out.println("价格:"+price+"元"); System.out.println("尺寸:"+size+"英寸"); } public void call(String yeye){ System.out.println("打电话给"+yeye); } public void playGames(String wzly){ System.out.println("玩"+wzly); } @Override public String toString() { return "Phone{" + "brand='" + brand + '\'' + ", price=" + price + ", size=" + size + '}'; } }
import java.util.Arrays; public class P1 { public static void main(String[] args) { Phone a = new Phone(); a.brand = "国产"; a.size = 8; a.price = 12000; a.shuxin(); a.call("朋友"); a.playGames("王者荣耀"); System.out.println("*******************"); Phone b = new Phone(); b.brand = "国产"; b.size = 8; b.price = 12000; b.shuxin(); b.call("朋友"); b.playGames("王者荣耀"); Phone[] arr = {a,b}; System.out.println(Arrays.toString(arr)); } }