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.
in the ProductConsumer class, but Netbeans gave me the same error message, "cannot find symbol: method messageList(), location: class ProductConsumer," so I need to create a method messageList() in ProductConsumer. Thanks.
modified 22-Dec-12 19:21pm.
Last Visit: 31-Dec-99 18:00 Last Update: 19-Mar-18 22:29