title: Extend class with default constructor in Java
body: <p>I need to extend <code>class A</code> but it needs to override its constructor.</p>
  
  <pre><code>package com.example.io; // Package belongs to jar from maven dependency
  
  public class A {
      A(String s, Integer i) {
          // constructor code
      }
  
      // other methods
  }
  </code></pre>
  
  <p>As it is default constructor (a constructor with only package access) I cannot access outside the package, so I created same package name in my source code <code>com.example.io</code> and extended <code>class A</code> and built successfully.</p>
  
  <pre><code>package com.example.io; // Package belongs to my source code
  
  public class B extends A{
      B(String s, Integer i) {
          super(s, i); // Throws error on runtime
      }
  
      // other methods
  }
  </code></pre>
  
  <p>But it throws runtime error saying - </p>
  
  <pre><code>java.lang.IllegalAccessError: tried to access method com.example.io.A.&lt;init&gt;(Ljava/lang/String;Ljava/lang/Integer;)V from class com.example.io.B
  </code></pre>
  
  <p>How do I solve this? I mean, is there any way I can extend class A with default constructor?</p>