How to overcome limitations of Java's Static Main() Method
<p>I'm trying to work this out.</p>

<p>In my project, i have a file called 'Hello.java' which is the file with the main() argument and which is called when the program is compiled. And I have another file called MyObj.java which has got just a random class I made up to test java's OO features. I'm trying to do this:</p>

<pre><code>class Hello
{
    public MyObj an_obj;
    public static void main(String[] args)
    { 
        setObj();
    }       

    public void setObj()
    {
        this.an_obj.set_size(7);
        say("size is " + this.an_obj.get_size());
    }    
}
</code></pre>

<p>In the MyObj.java class i have this code:</p>

<pre><code>public class MyObj
{
    private int size;

    public MyObj()
    {
        //do nothing
    }

    public void set_size(int new_size)
    {
        this.size=new_size;
    }

    public int get_size()
    {
        return this.size;
    }   
}
</code></pre>

<p>This however gives the error:</p>

<blockquote>
  <p>"Cannot make a static reference to
  non-static method setObj() from the
  type Hello".</p>
</blockquote>

<p>If I add 'static' to the declaration of setObj, i.e</p>

<pre><code>public static void setObj()
</code></pre>

<p>Then I get:</p>

<blockquote>
  <p>Cannot make a static reference to
  non-static field an_obj.</p>
</blockquote>

<p>My question is, how can I accomplish what I'm doing, i.e setting and retreiving an object's field if the only way to start a program is with the Main method, and the main Method can only call static methods?? In what, how can I do anything at all with this limitation of being able to call static methods only?????</p>
