title: How to call an Observer method from a different file?
body: <p>I'm new to Java and have been trying to program a file that calls from another file. Lets say I have file A.java and it has an observer method</p>
  <p>...</p>
  <pre><code>//in Item.java
  
  public class Item{
      private String name;
       
      //parametrized cons
      public Item(String name){
          this.name = name;    
      }
  
      public String getName(){
          return this.name;
      }
  }
  </code></pre>
  <p>And lets say in file B.java I want to print all Item.names, I thought it would be something like this</p>
  <pre><code>//in Bag.java
  public class Bag {
      private int size;
  
      public void print(){
          // this does not work 
          System.out.println(Item.getName());
      }
  }
  </code></pre>
  <p>But this didn't work. I can't change the method (name) of print at all. Is there another way this can be done?</p>
  <p>Goal: Sorry If I am not being clear, the goal is to print the name of an item. Assuming we passed an item to the Item.java class already, how would you print that item?</p>