title: Java Package and Access Modifier
body: <p>I created a Directory p1 under which I wrote a Demo.java program :-</p>
  
  <pre><code>package p1;
  
  public class Demo {
  
       public static void main(String[] args){
           Protection ob1 = new Protection();
           Derived ob2 = new Derived();
           SamePackage ob3 = new SamePackage();
      }
  }
  </code></pre>
  
  <p>Under the same Directory I wrote Program for Protection.java, Derived.java, SamePackage.java as follows :-</p>
  
  <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_pro = " + n_pro);
          System.out.println("n_pub = " + n_pub);
      }
  }  
  </code></pre>
  
  <p>and </p>
  
  <pre><code>package p1;
  
  class Derived extends Protection {
  
      Derived(){
          System.out.println("derived Constructor.");
          System.out.println("n = " + n);
  
          System.out.println("n_pro = " + n_pro);
          System.out.println("n_pub = " +n_pub);
      }
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>package p1;
  
  class SamePackage {
  
      SamePackage(){
          Protection p = new Protection();
          System.out.println("Same Package Constructor");
          System.out.println("n = " + p.n);
          System.out.println("n_pro = " + p.n_pro);
          System.out.println("n_pub = " + p.n_pub);
      }
  }  
  </code></pre>
  
  <p>But when I am doing javac Demo.java in p1 folder I am getting an error that it can't find Protection, Derived and SamePackage symbols. What could be wrong here where I am mistaken?
  Any lead will be thankfully appreciated.   </p>