class Foo { public int left = 9; public int right = 3; public void setLeft(int leftNum) { left = leftNum; right = leftNum/3; } // lots of complex test code here }
Now consider this question: Is the value of right always going to be one-third the value of left? It looks like it will, until you realize that users of the Foo class don't need to use the setLeft() method! Thay can simply go straight to the instance variables and change them to any arbitrary int value.
Refrence: SCJP Sun® Certified Programmer for Java™ 6 Study Guide Exam (310-065)
No comments:
Post a Comment