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

二、给"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));
}
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!