Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Had to create a testcase, since it's been so long, and this was always a sort of fuzzy area:</p> <pre><code>public class ConstrTest { protected String fieldA; protected String fieldB; public static void main(String[] argV) { ConstrTestSub sub1 = new ConstrTestSub("111", "222"); sub1.print(); // ConstrTestSub sub2 = new ConstrTestSub(); // sub2.print(); } public ConstrTest() { this("ABC","XYZ"); } public ConstrTest(String a) { this(a, "YYY"); } public ConstrTest(String a, String b) { fieldA = a; fieldB = b; } public void print() { System.out.println("fieldA = " + fieldA + ", fieldB = " + fieldB); } } class ConstrTestSub extends ConstrTest { private String fieldC; public ConstrTestSub(String a, String b) { super(a, b); fieldC = "QQQ"; } public void print() { System.out.println("fieldA = " + fieldA + ", fieldB = " + fieldB + ", fieldC = " + fieldC); } } </code></pre> <p>The above code compiles and runs fine, and the ConstTestSub constructor executes the corresponding <code>super</code> version appropriately (which it would do even without the explicit <code>super</code> invocation).</p> <p>If you uncomment the second <code>new ConstTestSub</code> in main, though, it will not compile, since the <code>()</code> version of the constructor is not defined.</p> <p>So, <strong><em>if</em></strong> you're going to define your constructors at all, and <strong><em>if</em></strong> you need multiple forms, you must define all the forms you need. (They can, of course, just be cascaded if that's sufficient.)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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