Problem with class instances
I always run into this problem for almost every single java program I write, and to this day I do not know what is wrong.
As an example, lets pretend im doing a binary search tree, I have the BST class seperate from my Main class.
The main class has certain numbers already saved, so what the main class does, is it creates an instance of the BST class called Root ( The bst class has a data field, and 2 BST instances itself, like a linked list, one for the left child, and one for the right child, so thats all set)
Now, what the Main class does, is it takes a single int value, and passes it into a method in the Main class called addValue().
addValue then uses an algorithm for binary search trees to add the value to the BST.
The problem I am running into is, that even tough an instance of the BST class exists in the main method of the main class, the addValue method in the main class cannot access it
Main method has something like this
BST root = new BST(); ( BST being a class)
Then the addValue method takes the value "x" that it has been passed and attempts to do this.
int value = x;
root.data=value (data is an int field in the BST class)
And basically it tells me that it has no idea what root is....Is this a limitation of java or what?