I am trying to implement Binary tree in java and here is my code:
class TestClass { public static void newnode(int a , Node root,){ root = new Node(a); System.out.println(root.data); // Printing out 22 } public static void main(String args[] ) throws IOException { Node root = null; newnode(22,root); System.out.println(root.data); // Giving NullPointerException } } class Node{ Node left ; Node Right; int data ; Node(int dataa){ this.data = dataa; } } I could not insert a new node in my tree , the value of root does not changes
When i call newnode function I getting the correct value of my Root Node but in the main function it gives me null point exception
Why the value of root is not updating