title: Error: Package p1 does not exist while compiling java file from package p2
body: <pre><code>package p1;
  public class Protection {
  
  int n = 1;
  private int n_pri = 2;
  protected int n_pro = 3;
  public int n_pub = 4;
  
  public Protection() {
      System.out.println("base constructor");
      System.out.println("n = " + n);
      System.out.println("n_pri = " + n_pri);
      System.out.println("n_pro = " + n_pro);
      System.out.println("n_pub = " + n_pub);
  }
  }
  </code></pre>
  
  <p>Package p2 contains three files demo.java, OtherPackage.java and Protection2.java:</p>
  
  <pre><code>//Demo package p2.
  package p2;
  
  //Instantiate various classes in p2.
  public class Demo {
  public static void main(String[] args) {
      Protection2 ob1 = new Protection2();
      OtherPackage ob2 = new OtherPackage();
  }
  }
  
  package p2;
  </code></pre>
  
  <p>OtherPackage.java</p>
  
  <pre><code>class OtherPackage {
  OtherPackage() {
      p1.Protection p = new p1.Protection();
      System.out.println("Other package constructor");
  
      //class or package only
      //System.out.println("n = " + p.n);
  
      //class only
      //System.out.println("n_pri = " + p.n_pri);
  
      //class, subclass or package only
      //System.out.println("n_pro = " + p.n_pro)
  
      System.out.println("n_pub = " + p.n_pub);
  }
  }
  </code></pre>
  
  <p>and Protection2.java</p>
  
  <pre><code>package p2;
  
  class Protection2 extends p1.Protection {
  Protection2() {
      System.out.println("Derived other package constructor");
  
      //class or package only
      //System.out.println("n = " + n);
  
      //class only
      //System.out.println("n_pri = " + n_pri);
  
      System.out.println("n_pro = " + n_pro);
      System.out.println("n_pub = " + n_pub);
  }
  }
  </code></pre>
  
  <p>I tried compiling Demo.java from package p2:</p>
  
  <pre><code>:~/Desktop/Examples/p2$ javac *.java
  </code></pre>
  
  <p>I generates the following errors</p>
  
  <pre><code>Protection2.java:3: error: package p1 does not exist
  class Protection2 extends p1.Protection {
                          ^
  OtherPackage.java:5: error: package p1 does not exist
      p1.Protection p = new p1.Protection();
        ^
  OtherPackage.java:5: error: package p1 does not exist
      p1.Protection p = new p1.Protection();
                              ^
  Protection2.java:13: error: cannot find symbol
      System.out.println("n_pro = " + n_pro);
                                      ^
      symbol:   variable n_pro
      location: class Protection2
  Protection2.java:14: error: cannot find symbol
      System.out.println("n_pub = " + n_pub);
                                      ^
      symbol:   variable n_pub
      location: class Protection2
  5 errors
  </code></pre>
  
  <p>I tried importing package p1 but it adds another error along with the above 5 errors:</p>
  
  <pre><code>Demo.java:4: error: package p1 does not exist
  import p1.Protection;
  </code></pre>