0
Is it good to take input from user inside constructor !?
7 Answers
+ 2
Abdul Wahab you're welcome.
And this is how super() works.
https://code.sololearn.com/cuqhcU7gFv8f/?ref=app
+ 2
I don't think if that is a practice that is encouraged but you can take all the user inputs inside the main method using local variables and then pass it to the constructor of an object that you want to instantiate.
+ 1
You would have handled it in a different way if there is inheritance involved, in that case super() could be used. But for this case you could do something like this.
Just an example.
https://code.sololearn.com/czrzYD2ZKFQN/?ref=app
+ 1
Ok then you can read on how to call super() from child class constructor to call parent class constructor. You can also pass arguments and the super() must be the first line inside the constructor.
Do a little research and you will understand it better.
+ 1
yeah sure i will watch videos. on utube .
thanks man â„ïž really appreciated
0
Avinesh nd wht about invoking other class constructor inside constructor
for example
Account(){
Person p = new Person()}
}
0
Avinesh yes inheritance is involed