title: How to inherit java classes (from one package) into another class (in another package)
body: <p>Java n00b here. I have been learning about packages lately and see them as really useful in managing code. However, I am (frequently) running into a problem of not being able to inherit a class from one package into a class of another package.</p>
  
  <p>Here's the code of <code>A.java</code> which has been created in <code>Package1</code>:-</p>
  
  <pre><code>package Package1;
  public class A
  {
      private int a;
  
      protected void setA(int a)
      {
          this.a = a;
      }
  
      public int getA()
      {
          return a;
      }
  
      public String toString()
      {
          return String.format("a = "+a);
      }
  }
  </code></pre>
  
  <p>The class that is inheriting is <code>A1.java</code> located in <code>Package2</code>. Its code is as follows:-</p>
  
  <pre><code>package Package2;
  import Package1.A;
  public class A1 extends A      // I even tried `Package1.A` but didn't have any change
  {
      private int a1;
  
      public void setA1(int a1)
      {
          this.a1 = a1;
      }
  
      public int getA1()
      {
          return a1;
      }
  
      public String toString()
      {
          return String.format("a1 = "+a1);
      }
  }
  </code></pre>
  
  <p>The error that I am getting is:-</p>
  
  <pre><code>A1.java:2: error: package Package1 does not exist
  import Package1.A;
                 ^
  A1.java:3: error: cannot find symbol
  public class A1 extends A
                          ^
    symbol: class A
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>A1.java:2: error: package Package1 does not exist
  import Package1.A;
                 ^
  A1.java:3: error: package Package1 does not exist
  public class A1 extends Package1.A
  </code></pre>
  
  <p>I am not understanding how to solve this problem. Can you please help?</p>