This commit is related to BAEL-6972 (#16217)
This commit aims to add two classes Child and Parent.
This commit is contained in:
parent
4912f824c9
commit
452cdc58c9
@ -0,0 +1,14 @@
|
|||||||
|
package com.baeldung.statementsbeforesuper;
|
||||||
|
|
||||||
|
class Child extends Parent {
|
||||||
|
Child() {
|
||||||
|
super(); // Or super(10); Correct placements
|
||||||
|
System.out.println("Child constructor");
|
||||||
|
additionalInitialization();
|
||||||
|
// super(); Compilation error: Constructor call must be the first statement in a constructor
|
||||||
|
}
|
||||||
|
|
||||||
|
private void additionalInitialization() {
|
||||||
|
System.out.println("Additional initialization in Child");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.baeldung.statementsbeforesuper;
|
||||||
|
|
||||||
|
public class Parent {
|
||||||
|
public Parent(int id) {
|
||||||
|
System.out.println("Parametrized Parent constructor");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Parent() {
|
||||||
|
System.out.println("Parent constructor");
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user