title: Object initialized in the main class and using the same object in a method/function for different purpose?
body: <p>I have a class that contains the following coding</p>
  <pre><code>import java.util.Scanner;
  import java.io.*;
  
  public class someClass {
  
      public static void main(String[] args) {
          Product[] p= new Product[3];
          p[0] = new Product();
          p[1] = new Product();
          p[2] = new Product();
          p[0].name=&quot;John&quot;;    // Product is a class which contains variable String name;  
                               // and a method getName() which is returning the name;
          p[1].name=&quot;Tony&quot;;
          p[2].name=&quot;Abraham&quot;;
          somePrintMethod();
      }
  
      public static void somePrintMethod() {
          for(int i =0;i&lt;3;i++) {
              System.out.println(p[i].getName());
          }
      }
  }
  </code></pre>
  <p>So my question is can I use the object defined in the main class in any other method for other</p>
  <p>purpose in the same class or there is any method to use that object because I am trying to</p>
  <p>do that and it is giving me an error and I cannot figure out how to do it.</p>