+ 2

Is it possible to call one constructor from another in Java?

21st May 2019, 8:31 PM
Omkar Shinde
Omkar Shinde - avatar
3 Answers
+ 8
Omkar Shinde Java constructor chaining is a method of calling one constructor with the help of another while considering the present object. Within same class: It can be done using this() keyword for constructors in the same class. source: https://data-flair.training/blogs/constructor-chaining-in-java/ I hope I was helpful
21st May 2019, 8:37 PM
Alessio Benvenuti
Alessio Benvenuti - avatar
+ 5
Omkar Shinde Do you mean this? In the constructor of the first class I created an object of the second class. As you can see, creating an object of first, both constructor are called. https://code.sololearn.com/cb6XKtn3O8gh/?ref=app
21st May 2019, 9:33 PM
Denise Roßberg
Denise Roßberg - avatar
+ 3
Yes
21st May 2019, 10:29 PM
Sonic
Sonic - avatar