So I see that when it's woman.husband = man; and man.wife = woman;, it passed through.
If it's the other way around (man = woman.husband or woman = man.wife), it does not pass condition 3 and 4.
Can someone please explain to me?
What's the difference between man = woman.husband and woman.husband = man ???
public class Solution {
public static void main(String[] args) {
Man man = new Man();
Woman woman = new Woman();
woman.husband = man;
man.wife = woman;
}
What's the difference?
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
6 March 2020, 21:56
because the operator '=' is called the assignment operator. It sets the variable on the right to the object on the left.
In your first example you are setting the husband and wife correctly to woman and man properly using a declared object. In the second example you are attempting to set an object using another uninitialized object.
So man and woman are both initialized using the 'new' keyword and then man.wife is set to the initialized object 'woman' and woman.husband is set to the initialized object 'man'
0