...
Code Block | ||
---|---|---|
| ||
public class Widget { private int total; void add (someType someParameter) { total++; // ... } void remove (someType someParameter) { total--; // ... } public int getTotal () { return total; } } |
Exceptions
Wiki Markup |
---|
*EX1:* According to \[[Conventions 09|AA. Java References#Conventions 09]\]: |
One example of appropriate
public
instance variables is the case where the class is essentially a data structure, with no behavior. In other words, if you would have used astruct
instead of a class (if Java supportedstruct
), then it's appropriate to make the class's instance variablespublic
.
Risk Assessment
Failing to declare data members private
can break encapsulation.
...