对初始化“类”的理解

一、"类"嵌套的情景演示

二、给"MobilePhoneConfiguration"初始化值

三、思想解析:

四、"嵌套类"的代码块

class MobilePhoneConfiguration {
    private String phoneMobile;
    private String phoneType;
    private String phoneOperatingSystem;
    private int phonePrice;
    private int phoneInternal;
    private PhoneFunction phoneFunction;

    public MobilePhoneConfiguration(String phoneMobile,
                                    String phoneType, String phoneOperatingSystem,
                                    int phonePrice, int phoneInternal,
                                    PhoneFunction phoneFunction) {
        this.phoneMobile = phoneMobile;
        this.phoneType = phoneType;
        this.phoneOperatingSystem = phoneOperatingSystem;
        this.phonePrice = phonePrice;
        this.phoneInternal = phoneInternal;
        this.phoneFunction = phoneFunction;
    }

    @Override
    public String toString() {
        return "MobilePhoneConfiguration{" +
                "phoneMobile='" + phoneMobile + '\'' +
                ", phoneType='" + phoneType + '\'' +
                ", phoneOperatingSystem='" + phoneOperatingSystem + '\'' +
                ", phonePrice=" + phonePrice +
                ", phoneInternal=" + phoneInternal +
                ", phoneFunction=" + phoneFunction +
                '}';
    }

    public String getPhoneMobile() {
        return phoneMobile;
    }

    public void setPhoneMobile(String phoneMobile) {
        this.phoneMobile = phoneMobile;
    }

    public String getPhoneType() {
        return phoneType;
    }

    public void setPhoneType(String phoneType) {
        this.phoneType = phoneType;
    }

    public String getPhoneOperatingSystem() {
        return phoneOperatingSystem;
    }

    public void setPhoneOperatingSystem(String phoneOperatingSystem) {
        this.phoneOperatingSystem = phoneOperatingSystem;
    }

    public int getPhonePrice() {
        return phonePrice;
    }

    public void setPhonePrice(int phonePrice) {
        this.phonePrice = phonePrice;
    }

    public int getPhoneInternal() {
        return phoneInternal;
    }

    public void setPhoneInternal(int phoneInternal) {
        this.phoneInternal = phoneInternal;
    }

    public PhoneFunction getPhoneFunction() {
        return phoneFunction;
    }

    public void setPhoneFunction(PhoneFunction phoneFunction) {
        this.phoneFunction = phoneFunction;
    }
}

//-------------------------------------------------------

class PhoneFunction {
    private String phoneCall;
    private String phoneGame;
    private String phoneMusic;

    public PhoneFunction(String phoneCall, String phoneGame, String phoneMusic) {
        this.phoneCall = phoneCall;
        this.phoneGame = phoneGame;
        this.phoneMusic = phoneMusic;
    }

    @Override
    public String toString() {
        return "PhoneFunction{" +
                "phoneCall='" + phoneCall + '\'' +
                ", phoneGame='" + phoneGame + '\'' +
                ", phoneMusic='" + phoneMusic + '\'' +
                '}';
    }

    public String getPhoneCall() {
        return phoneCall;
    }

    public void setPhoneCall(String phoneCall) {
        this.phoneCall = phoneCall;
    }

    public String getPhoneGame() {
        return phoneGame;
    }

    public void setPhoneGame(String phoneGame) {
        this.phoneGame = phoneGame;
    }

    public String getPhoneMusic() {
        return phoneMusic;
    }

    public void setPhoneMusic(String phoneMusic) {
        this.phoneMusic = phoneMusic;
    }
}

//-------------------------------------------------------

class TestMobilePhoneConfiguration {

    public static void main(String[] args) {
        MobilePhoneConfiguration mobilePhoneConfiguration[] = new MobilePhoneConfiguration[3];
//初始化过程
        mobilePhoneConfiguration[0] = new MobilePhoneConfiguration("XiaoMi",
                "Utral",
                "安卓系统",
                4000,
                128,
                new PhoneFunction("打电话", "打游戏", "听音乐"));

        mobilePhoneConfiguration[1] = new MobilePhoneConfiguration("HuaWei",
                "Utral",
                "鸿蒙系统",
                8000,
                256,
                new PhoneFunction("打电话", "打游戏", "听音乐"));

        mobilePhoneConfiguration[2] = new MobilePhoneConfiguration("Apple",
                "IOS系统",
                "苹果",
                5000,
                256,
                new PhoneFunction("打电话", "打游戏", "听音乐"));

        System.out.println("手机配置:");
        for (MobilePhoneConfiguration m : mobilePhoneConfiguration) {
            System.out.println(Arrays.asList(m));
        }

    }
}

posted on   陈嘻嘻-  阅读(25)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示