BAEL-5131: constructor specification is added c (#11586)

* BAEL-5131: constructor specification is added c

* BAEL-5131: codes have been reformatted

* BAEL-5131: I've added a few minor changes over on this package.

* BAEL-5131: I've added a few minor changes over on this package.
This commit is contained in:
Arash Ariani 2022-01-23 01:25:53 +03:30 committed by GitHub
parent 7ad433dcb6
commit db396b39a9
6 changed files with 89 additions and 0 deletions

View File

@ -0,0 +1,24 @@
package com.baeldung.constructorspecification.rules;
class Employee extends Person {
int id;
public Employee() {
super();
}
public Employee(String name) {
super(name);
}
public Employee(int id) {
this();
//super("John"); // syntax error
this.id = id;
}
public static void main(String[] args) {
new Employee(100);
}
}

View File

@ -0,0 +1,14 @@
package com.baeldung.constructorspecification.rules;
class Person {
String name;
public Person() {
this("Arash");
}
public Person(String name) {
this.name = name;
}
}

View File

@ -0,0 +1,12 @@
package com.baeldung.constructorspecification.rules;
class RecursiveConstructorInvocation {
public RecursiveConstructorInvocation() {
RecursiveConstructorInvocation rci = new RecursiveConstructorInvocation();
}
public static void main(String[] args) {
new RecursiveConstructorInvocation(); // java.lang.StackOverflowError
}
}

View File

@ -0,0 +1,14 @@
package com.baeldung.constructorspecification.simple;
class Person {
String name;
public Person() {
this("Arash"); //ExplicitConstructorInvocation
}
public Person(String name) {
this.name = name;
}
}

View File

@ -0,0 +1,15 @@
package com.baeldung.constructorspecification.superclass;
class Employee extends Person {
String name;
public Employee(int id) {
super(id); //ExplicitConstructorInvocation
}
public Employee(int id, String name) {
super(id);
this.name = name;
}
}

View File

@ -0,0 +1,10 @@
package com.baeldung.constructorspecification.superclass;
class Person {
int id;
public Person(int id) {
this.id = id;
}
}