Results 1 to 3 of 3

Thread: Question about this method.

  1. #1

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    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.

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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

  3. #3

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    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
  •  



Click Here to Expand Forum to Full Width