Question about this method.
Code:
Here's a simple example:
class Bird {
int xPos, yPos;
double fly ( int x, int y ) {
double distance = Math.sqrt( x*x + y*y );
flap( distance );
xPos = x;
yPos = y;
return distance;
}
...
}
Can someone explain what this part:
flap( distance );
does, or what is happening with it? How is it being used? Is it a method inside the fly method?
Also:
Code:
class Bird {
int xPos, yPos;
int xNest, yNest;
...
double flyToNest( ) {
int xPos = xNest;
int yPos = yNest:
return ( fly( xPos, yPos ) );
}
...
}
How is the return statement working here?
return ( fly( xPos, yPos ) );
I know these are examples, but they are confusing me as it seems they are leaving things out. Whats being left out?
Thanks in advance for clearing it up.
Re: Question about this method.
There are no such thing as a method inside a method in Java.
I guess this code is part of a GUI program that displays the movement of the bird while it's moving to nest.
Code:
void flap(int distance)
is a method within the same class Bird called to move the Bird horizontally.
The method flyToNest makes modification to the values xPos, yPos calls the method fly with the arguments xPos, yPos and returns the return value of the method fly as it's own return value.
Re: Question about this method.
ahh, so its a call to the method flap from the method fly that passes the argument distance.
also, so you can, can call a method from a return statement.
wow