Re: Ways to call a method
Ericsson wrote:
public class MaximumFinder
{
// obtain three floating-point values and determine maximum value
public void determineMaximum()
{
// determine the maximum value
double result = maximum( number1, number2, number3 );
} // end method determineMaximum
// returns the maximum of its three double parameters
public double maximum( double x, double y, double z )
{ }
} // end class MaximumFinder
As others have said, you are over reading this.
Look at the code above. I've simply snipped your example so the lines
are easier to find. See in the second bit where the comment says:
// determine the maximum value
That's what they mean. The method "maximum" is invoked on the line
right after that comment. It just calls the method "maximum" in the
same class. The line right after:
// returns the maximum of its three double parameters
That method right after than comment is invoked.
All it means is you can call methods from the same class with out using
the class name or the instance variable. The compiler will figure out
what you mean and do it. The call above is the same as calling:
double result = this.maximum( number1, number2, number3 );
"this" means "this instance variable" so you just call the a method
that's already in you class.
The only tricky bit is when you call a method that isn't declared
directly. For example, right after the call to maximum(), you could
have added:
String me = toString();
This calls your (instance of class MaximumFinder) toString() method.
Well you don't see one, but you have it, because you inherit toString()
from Object, which all classes subclass from. You'll run into methods
that a class inherits quite a bit. It's best to have a modern IDE so
you can quickly find where any method is declared. They can sometimes
come from unexpected places and won't be obvious like maximum() was.
Good luck.