The second statement calls the move()
method of the Point
,but does not supply information about where to move the point.
In this case, saying what method to run is not enough.The method needs information about what it is to do.When you look at the description of class Point
the move()
method is described as follows:
public void move(int x, int y); // change (x,y) of a point object
This description says that the method requires two parameters:
int
. It will become the new value for x.int
. It will become the new value for y.Dot notation is used to specify which object, and what method ofthat object to run.The parameter list of the method supplies the method with data.Here are some examples:
Point pointA = new Point();Point pointB = new Point( 94, 172 );pointA.move( 45, 82 );int col = 87;int row = 55;pointA.move( col, row );
You can put expressions into parameter lists as long as the expression evaluates to the type expected by the method. Of course, the expressions are evaluated (using the usual rules) before the method starts running.
pointB.move( 24-12, 30*3 + 5 );pointB.move( col-4, row*2 + 34 );
What is the location of pointB
after the following: