首页 > 其他分享 >对初始化“类”的理解

对初始化“类”的理解

时间:2022-12-05 23:11:18浏览次数:35  
标签:初始化 return String phoneInternal PhoneFunction 理解 phoneMusic public

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

二、给"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));
        }

    }
}

标签:初始化,return,String,phoneInternal,PhoneFunction,理解,phoneMusic,public
From: https://www.cnblogs.com/chen-zhou1027/p/16953859.html

相关文章

  • 1500PLC,编程理解
    一,DB块,FB块的高级应用1,同一个FB快可以通过不同的DB快调用,该DB快调用FB快之后,该DB快中的局部变量可以在调用该FB块的FB快内使用,有点拗口:FB400位住线体程序,包含该线体所有......
  • Vue2(笔记19) - 组件 - 对组件的理解
    传统方式写应用传统方式做项目:一个页面一个html,每个页面都会引入几个js 和css,代码交叉复制、文件交叉引用;存在的问题:1)依赖关系混乱,不好维护;2)代码复用率不高;模块化:理解:......
  • 1.1初始化配置MYSQL服务器
    /*初始配置服务器,需先根据操作系统下载MicrosoftAccess2010数据库引擎AccessDatabaseEngine_X64.exe(https://www.microsoft.com/zh-cn/download/confirmation.aspx?id......
  • SpringMvc个人理解
    SpringMvc执行流程(1)浏览器提交请求到中央调度器(2)中央调度器直接将请求转给处理器映射器。(3)处理器映射器会根据请求,找到处理该请求的处理器,并将其封装为处理器执行链后返回......
  • React后台管理系统 02样式初始化,引入reset-css
    上一篇中,我们已经对项目的整体结构进行了搭建,现在需要对不需要的东西进行删除,最后留下这些东西。现在需要对全部的样式进行清除,使用命令导入依赖:npmireset-css然后在m......
  • 源码解析:Dubbo3 的 Spring 适配原理与初始化流程
    Dubbo国内影响力最大的开源框架之一,非常适合构建大规模微服务集群的,提供开发框架、高性能通信、丰富服务治理等能力。同时Dubbo无缝支持Spring、SpringBoot模式的开......
  • 关于DDD理解
    Domain:实体类、事件、防腐层接口、仓储接口、领域服务。Infrastructure(基础设施):实体类的配置、DbContext、防腐层接口实现、仓储接口实现。1WebAPl:Controller、事件(领域......
  • 文件上传的multipart/form-data属性,你理解了吗
    form表单经常用于前端发送请求,比如:用户填写信息、选择数据、上传文件,对于不同的场景,上传数据的格式也会有些区别。actionaction表示该请求的url地址,定义在form上,请求......
  • 5.shell命令及权限理解
    Shell及权限理解本文将介绍Shell是什么以及Linux中的权限。可以想一想在我们使用计算机的过程中,我们使用图形化界面或者命令行操作与计算机进行交互,是直接与内核进行交互......
  • 跨链技术学习理解(一)公证人机制、哈希锁定
    跨链资产交换问题两个用户在两个链上都有相应的账户,一个用户如何在用A链上的资产交换另一个用户在B链上的等价另一种资产。比如肥兔子想用1个比特币换豆畜子的10个以太。......