创建类的对象p1 p2,给对象的属性赋值,并且调用方法 把p1 和 p2 存放在一个数组中,并输出打印

1.Phone

public class Phone {
    //品牌
    String brand;
    double price;
    double size;

    public void call(int cal) {
        System.out.println("给xx打电话:" + cal);
    }

    public void playGames(String games) {
        System.out.println("玩的游戏是:" + games);
    }

    @Override
    public String toString() {
        return "Phone{" +
                "brand='" + brand + '\'' +
                ", price=" + price +
                ", size=" + size +
                '}';
    }
}

2.Phone_main

import java.util.Arrays;

public class Phone_mian {
    public static void main(String[] args) {
        Phone phone1 = new Phone();
        phone1.brand = "iphone15promax";
        phone1.price = 9999;
        phone1.size = 8;
        phone1.call(2);
        phone1.playGames("sss");
        System.out.println(phone1.brand);
        System.out.println(phone1.price);
        System.out.println(phone1.size);

        System.out.println("*******************");

        Phone phone2 = new Phone();
        phone2.brand = "iphone15pro";
        phone2.price = 999;
        phone2.size = 6;
        phone2.call(11111);
        phone2.playGames("gfg");
        System.out.println(phone2.brand);
        System.out.println(phone2.price);
        System.out.println(phone2.size);


        Phone[] phones = new Phone[]{phone1, phone2};
        System.out.println(Arrays.toString(phones));
    }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值