title: How to access non-static variables & methods from a different class
body: <p>I do not quite understand the use of "static" properly.</p>
  
  <p>I have a class which includes variables that I want to access from a different class.</p>
  
  <p>However, when I try to access this getter method from the different class I get an error stating:</p>
  
  <p>"non-static method getAccNumber() cannot be referenced from a static context."</p>
  
  <p>So, how can I find this variable's value without making it static. The problem with this is if I make it static, every instance of this object overwrites the previous value.
  So they all end up with the same account number in this case.</p>
  
  <p>Let me explain in more detail:</p>
  
  <p>I have a Class called Account, which contains a variable called accountNumber, and a getter method called getAccNumber().
  I have a second class called AccountList which is a separate arraylist class to store instances of Account. I want to create a method to remove an element based upon its accountNumber. So I'm searching and using getAccnumber() within the AccountList class to compare with a user parameter and removing if correct!
  But I can't use this method without making it static!! 
  Any help/explanation would be greatly appreciated :)</p>
  
  <p>This is what I am trying to do:</p>
  
  <pre><code>public boolean removeAccount(String AccountNumber)
  
  {   
  
  
      for(int index = 0; index &lt; accounts.size(); index++)
  
      {
  
      if (AccountNumber.equals(Account.getAccNumber()))
     {
  
          accounts.remove(index);
          return true;
      }
  }
      return false;
  }
  </code></pre>
  
  <p>Thank you!</p>