How does the evaluation take place, if say suppose all three methods return a String?
Originally posted by Jayashree M:
Suppose we have something as follows:
How does the evaluation take place, if say suppose all three methods return a String?
"If you want your dog to run, do you talk [to] your dog or to each leg? Further, should you be able to manipulate the dog's leg without it knowing about it? What if your dog wants to move its leg and it doesn't know how you left it? You can really confuse your dog."
The moral: Change the state of a contained object only through the containing object's interface.
"Aha!" you say. "If I employ the technique of encapsulation, then a method won't even know of the existence of any contained objects."
That's precisely the point. To walk your dog, you don't need to know of the existence of its legs. (And in fact, dogs with fewer than four legs can go for walks. There is even a case of a dog whose hindquarters rested on a little carriage; its "walk" method employed two legs and two wheels (these latter, one hopes, encapsulated within a "carriage" interface).)