title: Java Inheriting a public class with Package Private Constructor
body: <p>I come from a C++ background, I was just going through Access-Modifiers in Java and I decided to play around with some code and now I am getting an error: </p>
  
  <blockquote>
    <p>YouArePublic() is not public in YouArePublic; cannot be accessed from
    outside package</p>
  </blockquote>
  
  <p>I am not sure why. I know that the Constructor in class YouArePublic is default and hence I can't create an object of it in any other class outside its own package but I am not really creating an object here.</p>
  
  <p>Does the compiler implicitly tries to create an object of Tester class thus calling its default parameter-less constructor which is then invoking the constructor of its superclass YouArePublic using super()? but then main() is static so it doesn't need to create an instance of the class to invoke it.</p>
  
  <p>I am not sure what is happening here, Really need some help. </p>
  
  <pre><code>package one;
  
  import two.YouArePublic;
  
  class Tester extends YouArePublic { // Inheritance in different package
      public static void main(String args[]) {
  
          Tester ot = new Tester();
          ot.displayMessage();
  
      }
  }
  
  
  package two;
  
  public class YouArePublic {
      String message = "You are public in package TWO!";
  
      YouArePublic() { super(); }
  
  
      public void displayMessage() {
          System.out.println(message);
      }    
  }
  </code></pre>