Subsections
- Provide an object reference and the method name, separated by a dot (.):
fred.speak();
- Parameters are passed to methods as a comma-separated list.
- A method can return a single value as a result, such as an int:
public int add (int a, int b)
{
return a+b;
}
- A method can return no result:
public void setFirstName (String firstName)
{
this.firstName = firstName;
}
|
|