遇到问题,我想知道我this是否正确使用.
这个可以吗?
public person{
.
.
.
public void setmother(person mom){
mom.addchild(this);
}
Run Code Online (Sandbox Code Playgroud)
我创造了一个personb班级.在setmother中,我想使用一种方法将子类添加到类中.我想将类的当前实例添加到类的mom实例中的子数组中.
我甚至不知道我的语言是否有所下降...希望有人理解我正在做的事情!
我不确定如何在Java中使用枚举.我在以下示例中正确使用它吗?
enum Sex {M, F};
public class person{
private person mom;
private Sex sex;
public person(Sex sex){
this.sex = sex;
//is this how i'd set sex?
}
public void setMom(person mom){
if(mom.sex == 'M'){}
//is this how i would check to see if the sex of the passed person argument is male?
}
}
Run Code Online (Sandbox Code Playgroud) java ×2