Results 1 to 4 of 4

Thread: Calling Methods

  1. #1
    bluegreen7hi is offline Member
    Join Date
    Nov 2007
    Posts
    12
    Rep Power
    0

    Default Calling Methods

    Hi, I have a question that is probably pretty simple to most of you, but I am confused. What is the correct way to make the main method call another method? For instance, if I want the main method to execute method 1 then method 2, how would I go about typing that out?

  2. #2
    apfroggy0408 is offline Member
    Join Date
    Dec 2007
    Posts
    26
    Rep Power
    0

    Default

    Java Code:
    public static void main(String args[]);
    computemethod();  <----- Calls first method
    computenextmethod(); <----- Calls second method
    
    public void computemethod()
    {
    Method 1.
    }
    
    public void computenextmethod()
    {
    Method 2.
    }
    hope that helps

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    You have to think about parameters and return values of a method as well. And also you can't referenced non-static method from a static method also.

  4. #4
    newmember is offline Member
    Join Date
    Dec 2007
    Posts
    8
    Rep Power
    0

    Default

    In order to reference non-static methods , you will have to create object of the class in main and call those methods.

Similar Threads

  1. method calling?
    By frejon26 in forum New To Java
    Replies: 4
    Last Post: 01-25-2008, 03:38 AM
  2. Constructor calling
    By ravian in forum New To Java
    Replies: 2
    Last Post: 12-22-2007, 06:53 PM
  3. Calling Java methods form Python
    By mew in forum Advanced Java
    Replies: 1
    Last Post: 12-21-2007, 02:30 PM
  4. Problems with readLine() and calling methods
    By peachyco in forum New To Java
    Replies: 2
    Last Post: 11-24-2007, 07:44 AM
  5. need help calling methods
    By lowpro in forum New To Java
    Replies: 2
    Last Post: 11-15-2007, 09:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •