title: Using array of objects amd methods from one class in another class errors - JAVA
body: <p>I'm fairly new to Java and I'm struggling to understand a few concepts. What I am trying to achieve is constructing a Magazine in Magazine class, which requires an array of objects from the Supplement class in its constructor. I've created a method inside Supplement which fills up an array of objects of supplements, and I'm trying to call this method inside Magazine to fill up another supplement object I have created in there. Then, I am trying to pass that array of objects to the Magazine constructor so that one magazine can have this array of 4 supplements. Make sense?
  The problem I'm facing firstly, is that my method fillArray is not recognized in Magazine from class Supplement. All my classes are under the same source package, so what's the problem here? Some feedback on where I may be going wrong with my logic some guidance in the right direction would be helpful as I have to apply this logic for some other associated classes as well and I'm not quite sure how to go about it.</p>
  
  <p>Another question I have, is that upon doing some research I see that some people use public static void main(String args[]) in their classes for some operations. What is the purpose of this, as I thought it was only used inside the client program, and if it is used in classes what would be the use of the client program?</p>
  
  <p>Magazine.java:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class Magazine {
      private String magazinename;
      private int WeeklyCost;
      private Supplement[] supplement;
  
      public static void main(String args[]){
  
          Supplement[] supplements = new Supplement[3];
          supplements.fillArray();
  
          Magazine magazineobj = new Magazine("The Wheels Special", 35, supplements);
      };
  
      public void SetMagazineName(String magazinename1){    
          magazinename = magazinename1;
      };
  
      public void SetWeeklyCost(int WeeklyCost1){
          WeeklyCost = WeeklyCost1;    
      };
  
      public String GetMagazineName(){        
          return magazinename;
      };
  
      public int GetWeeklyCost() {        
          return WeeklyCost;
      };
  
      public void SetMagazine(String magazinename1, int WeeklyCost1, Supplement[] supplements1){
              magazinename = magazinename1;
              WeeklyCost = WeeklyCost1;
              supplement = supplements1;
      };
  
      public Magazine(String magazinename1, int WeeklyCost1, Supplement[] supplements1){
          SetMagazine(magazinename1,WeeklyCost1,supplements1);
      };
  }
  </code></pre>
  
  <p>Supplement.java:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class Supplement {
      private String supplementname;
      private int WeeklySupCost;
  
      Supplement[] supplements = new Supplement[3];
  
      public void fillArray(){ 
          supplements[0] = new Supplement("Sports Illustrated Special", 4);
          supplements[1] = new Supplement("Health and Nutrition", 2);
          supplements[2] = new Supplement("Lifestyled", 5);
          supplements[3] = new Supplement("Gamer's Update", 3);
       }
  
      public void SetSupplementName(String supplementname1){ 
          supplementname = supplementname1;
      };
  
      public void WeeklySupCost(int WeeklySupCost1){
          WeeklySupCost = WeeklySupCost1;
      };
  
      public String GetSupplementName(){
          return supplementname;
      };
  
      public int GetWeeklyCost(){        
          return WeeklySupCost;
      };
  
      public void SetSupplement(String supplementname1, int WeeklySupCost1){
          supplementname = supplementname1; 
      };
  
      public Supplement(String supplementname1, int WeeklySupCost1){
          SetSupplement(supplementname1, WeeklySupCost1);
      }
  }
  </code></pre>