Answer the question
In order to leave comments, you need to log in
What's the best way to deal with a constructor?
What is the correct way to assign a new address through the add function to the variable second and then left, right, etc.?
public class First {
Second second;
public First() {
second = null;
add(second);
}
public void add(Second sec) {
sec = new Second(11);
sec.left = new Second(15);
}
}
public class Second {
public Second left;
public Second right;
public Integer value;
public Second(Integer value) {
left = null;
right = null;
this.value = value;
}
}
Answer the question
In order to leave comments, you need to log in
public class First {
Second second;
public First() {
second = add(second);
}
public Second add(Second sec) {
sec = new Second(11);
sec.left = new Second(15);
return sec;
}
}
class Second {
public Second left;
public Second right;
public Integer value;
public Second(Integer value) {
this.value = value;
}
}
public class First {
Second second;
public First(int value, int left, int right) {
second = new Second(value, left, right);
}
public First(int value) {
second = new Second(value);
}
}
class Second {
public Second left;
public Second right;
public int value;
public Second(int value, int left, int right) {
this.value = value;
this.left = new Second(left);
this.right = new Second(right);
}
public Second(int value) {
this.value = value;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question