mara sam wrote:I understood the increment() is a method and it is in class Leaf. But in this case the code is Leaf increment() {...} and why did the complier put a class name in front of the method name?
First: the compiler did nothing. You did.
But, to answer your question: the
Leaf is what the method
returns. You notice that the method contains a '
return this' statement, and
that is what returns the
Leaf object. If it didn't, you wouldn't be able to use '
increment().increment()', because the 2nd
increment() would have nothing to work with.
HIH
Winston