This commit is related to BAEL-6972 (#16217)

This commit aims to add two classes Child and Parent.
This commit is contained in:
MohamedHelmyKassab 2024-03-26 00:18:39 +02:00 committed by GitHub
parent 4912f824c9
commit 452cdc58c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 0 deletions

View File

@ -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");
}
}

View File

@ -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");
}
}