|
-
Dec 9th, 2005, 08:24 PM
#1
Thread Starter
Hyperactive Member
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.
Last edited by gjon; Dec 9th, 2005 at 08:33 PM.
-
Dec 10th, 2005, 12:05 AM
#2
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.
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Dec 10th, 2005, 01:22 AM
#3
Thread Starter
Hyperactive Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|