title: Call a method in another class within 3 classes in java
body: <p>I've 3 classes in one package. The first class (<code>ClassStart</code>) generates each an instance of the 2 other classes (<code>ClassA</code> and <code>ClassB</code>). I want to call in <code>ClassB</code> a method of <code>ClassA</code> by means of its instance "a".<br>
  Though the scope of Instance "a" is the package (because of the attribute <code>"ClassA a;"</code> in <code>ClassStart</code> the line <code>"a.showText()"</code> doesn't work. It gets the error message <code>"a cannot resolved"</code>.
  So I tried <code>"s.a.showText()"</code> but it doesn't work because the instance "s" was generated in a static method and I don't know how to access to "s".</p>
  
  <p>The first class (contains the main-method):  </p>
  
  <pre><code>public class ClassStart {
      ClassA a;
  
      public static void main(String[] args) {
      ClassStart s = new ClassStart();
      }
  
      public ClassStart() {
      a = new ClassA();
      ClassB b = new ClassB();
      }
  }
  </code></pre>
  
  <p>The second class:</p>
  
  <pre><code>public class ClassA {
  
      public void showText() {
      System.out.println("This text comes from ClassA.");
      }
  }
  </code></pre>
  
  <p>The third class:</p>
  
  <pre><code>public class ClassB {
  
      public ClassB() {
      a.showText();
      }
  }
  </code></pre>
  
  <p>How can I call in ClassB the method "showText()" of the ClassA?<br>
  (I had looked for answers in this forum but I didn't find a answers for a three class problem like this.) Thank you for answer.</p>