gpt4 book ai didi

java - 关于构造函数的困惑

转载 作者:行者123 更新时间:2023-12-01 14:43:15 37 4
gpt4 key购买 nike

Consider the following segment of code.

SomeClass someObject1 = new SomeClass("Computer Science");
SomeClass someObject2 = new SomeClass("Computer Science", "Rocks");
SomeClass someObject3 = new SomeClass("Computer", "Science", "Rocks");

Write complete constructors for each of these statements including the assignment of variables.

我不确定这个问题到底在寻找什么。有人可以帮我解决这个问题吗?

最佳答案

所以你的答案是

public SomeClass{

String str1;
String str2;
String str3;

public SomeClass(String str1){
this.str1=str1;
};
public SomeClass(String str1,String str2){
this.str1=str1;
this.str2=str2;
};
public SomeClass(String str1,String str2,String str3){
this.str1=str1;
this.str2=str2;
this.str3=str3;
};

}

关于java - 关于构造函数的困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15726075/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com