+ 1
Why we need more than one constructor in a class?
4 Antworten
+ 4
Because you may know different amounts of information about the objects you want to create at different times.
+ 3
Please specify the language in Relevant Tags section, and remove people's names from there 👍
+ 2
Sometimes you only need one.
+ 1
Not always, but sometimes it is a good practice. Let's create a class MyInt that stores only an int. It has two constructors, one which takes an int and the other takes nothing. If you want to create a MyInt object but want to set up the class later, you can use the constructor that takes nothing. Overall, having more than one constructor extends your class and can make it more flexible.