title: Access a class object from a method outside the main
body: <p>Sorry if the title isn't as accurate as it should be or maybe even falesly translated on my part. I'm german and a beginner in coding so take it easy one me.
  So I coded a programm in JAVA. It is a programm for a bank account that I picked up in a book and tried to expand. Now, to keep it simple in this thread I obviously reduced my example code on the problem. </p>
  
  <pre><code>public class Test1 {
  public static void method(){
      k.setNumber(300);  // This is where the problem is. From this method 
                         // I cannot acces the in main created class 
                         // object from 'Test'
      }
  
  public static void main(String[] args) {
  
      Test k = new Test();
  
      method();
      k.getNumber();
  
  }
  
  }
  </code></pre>
  
  <p>Now the class 'Test:</p>
  
  <pre><code>public class Test {
  
  int number;
  
  public int getNumber(){
      return number;
  }
  
  public void setNumber(int nr){
      number = nr;
  }
  }
  </code></pre>
  
  <p>So is there any way around it? Otherwise I would have to write everything in the 'main', which is no problem in the case of this example, but in my original code thats not so easy to do.</p>
  
  <p>Thanks for any help and advise. Hopefully this wasn't posted before because I already searched this site and the web.</p>