+ 4
What is the use of constructor Chaining in Java programming?
Any use and who to use it in Java programming
4 Antworten
+ 4
You can use it so you'll only need to write a specific code once in one constructor, so you dont need to write it again. Or also you can use them to create object with default value client doesnt pass the parameters.
For example you decide to extends a JFrame class. There's no way we know how the jframe are initiated. But with chaining we can call the constructor from JFrame to run as ours by calling super() we can also add additional code after call super(). here's an example
https://code.sololearn.com/cImahYGS8N1I/?ref=app
+ 3
Combin the constructors in one class
+ 2
One of the pillars of oops concept is INHERITANCE. Inheritance helps in code reusability . To achieve this , dont you think , we need to call the parent class .
To call the parent class , Constructor chain is used.... as simple as that....