'How to keep class or class instance address in second class's reference?

I was trying to build a binary decision diagram. It is just like a binary tree. When I have built the decision tree, all the terminal nodes should either point to a true value or a false value. I used a class Node to represent a binary tree that has two references. In the end, depending on their left_value and right-value, those terminal nodes should point to either a class whose value is false or true ;

Below is the Node which I used to build my BDD.

class Node{
boolean value;
char name;
boolean left_value;
boolean right_value;
Node right;
Node  left;

Node(char name, boolean value){
this.name = name ;
this.value= value;
right = null;
left = null;
}
}

class One{
boolean value = true;
}

class Zero{
 boolean value false;
}

Now if this is a terminal node meaning that it is the last node that doesn't point to any node. Now what I want is that I want it to point to either one or zero class depending on those left_value and righ_value.

Like this.

 public void point_to_class(Node node){
    if(node.left == null && node.right == null){
    if(node.left== true){
    node.left = new One();
    } else node.left = new Zero();
    
    if(node.right == true){
    node.right  = new One():}
    else node.right = new Zero();
}
}

In this case, it is throwing an error on the line node.right = new Zero(); but it doesn't give an error when I write node.right = new Node();

Does it have something to do with class attributes or methods? Because One and Zero classes don't have attributes and methods that the Node class has.

Please help me to find a solution.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source