I am currently working on a Generic Binary Search Tree. The insertion is done according to a variable - int seqNo and the get and set methods for seqNo are in a class called AnyClass (which is in a package named dataobjects).
Now, when I am calling the getseqNo() method in the BST class, it seems that it cannot be found.
I also have a class named Node that creates the nodes for the BST.
Please view the following link - the tutorial is a tutorial labelled "The Jvava Tutorial" which has a section catered to annotations:
You have to protect variables, because you depend in them.
Limiting the access to the getter and setter, you can depend on the variables to be used in the context you expect to have them.
Also, you can validate the value on the setter, which gives you the chance to to reject the value in case it is not ok (throw Exception). This protects your code from failing.
As a 3. argument: The same variable can be part of different methods/classes. but each name of a variable has to be unique, otherwise the code will fail.
So one limits down the range, where the variable exists as much as possible. therefor, one can use the same name again - not that one does it constantly, but one has the chance to.
And last but not least: it's simply good design/style to do so.
The usage of static should also be limited as much as possible.
There are some occasions where it is needed - but that should be used as less as possible.
Please read about the "encapsulation" - the link, that Richard posted. And please do some more research.
This is a basic of java development. One can't go without this, so you need to understand it.