Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>According to the Java Spec (<a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-6.html#jls-6.6.2.2" rel="noreferrer">https://docs.oracle.com/javase/specs/jls/se8/html/jls-6.html#jls-6.6.2.2</a>)</p> <blockquote> <h3>6.6.2.2. Qualified Access to a <code>protected</code> Constructor</h3> <p>Let <code>C</code> be the class in which a <code>protected</code> constructor is declared and let <code>S</code> be the innermost class in whose declaration the use of the <code>protected</code> constructor occurs. Then:</p> <ul> <li><p>If the access is by a superclass constructor invocation <code>super(...)</code>, or a qualified superclass constructor invocation <code>E.super(...)</code>, where <code>E</code> is a <em>Primary</em> expression, then the access is permitted.</p></li> <li><p>If the access is by an anonymous class instance creation expression <code>new C(...){...}</code>, or a qualified anonymous class instance creation expression <code>E.new C(...){...}</code>, where <code>E</code> is a <em>Primary</em> expression, then the access is permitted.</p></li> <li><p><strong>If the access is by a simple class instance creation expression <code>new C(...)</code>, or a qualified class instance creation expression <code>E.new C(...)</code>, where <code>E</code> is a <em>Primary</em> expression, or a method reference expression <code>C :: new</code>, where <code>C</code> is a <em>ClassType</em>, then the access is not permitted.</strong> A <code>protected</code> constructor can be accessed by a class instance creation expression (that does not declare an anonymous class) or a method reference expression only from within the package in which it is defined.</p></li> </ul> </blockquote> <p>In your case, access to the protected constructor of <code>A</code> from <code>B</code> would be legal from a constructor of <code>B</code> through an invocation of <code>super()</code>. However, access using <code>new</code> is not legal.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload