class Node{
int data;
Node left, right;
public Node(){
data=0;
left=null;
right=null;
}
}
public class aaa{
public static void main(String[] args){
Node x=new Node();
Node y=new Node();
x.left = y;
y.data = 5;
System.out.println(x.left.data);
}
}
Maybe this is what you were looking for.
What you were doing was setting X’s left to a node that wasn’t even created in the first place.(No actually you were doing the opposite, which again is the source of your confusion).
Hope this helped.