Results 1 to 4 of 4
  1. #1
    christina is offline Member
    Join Date
    Jul 2007
    Posts
    39
    Rep Power
    0

    Default non-static member can not be referenced from a static context

    If for every program I write a main function , which is a static method how am I supposed to call other non static functions from that?
    thanks

  2. #2
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    Instantiate the object.

    Java Code:
    public class MyObject
    {
    private void privateMethod() { /*do stuff*/ }
    
    public static void main(String[] args)
    {
    MyObject mo = new MyObject();
    mo.privateMethod();
    }
    }

  3. #3
    rock_star is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default

    christina,

    brian has answered your question but why do you want to have main method for each class?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Even more important: why are you asking this question in a thread from 2007?

Similar Threads

  1. Using Static Variables
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 12:08 AM
  2. Replies: 0
    Last Post: 04-17-2008, 12:07 AM
  3. Static class
    By eva in forum New To Java
    Replies: 1
    Last Post: 12-31-2007, 02:02 PM
  4. Replies: 1
    Last Post: 08-07-2007, 06:05 AM
  5. Replies: 1
    Last Post: 08-01-2007, 10:25 PM

Posting Permissions

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