+ 1

in one class how many constructors define?

17th Nov 2016, 5:24 PM
Dhaval Patel
Dhaval Patel - avatar
6 Réponses
+ 4
you can define many constructor as you required
17th Nov 2016, 6:17 PM
Harish Nandoliya
Harish Nandoliya - avatar
+ 2
There is always a default constructor. you can create your custom constructors with the help of function overloading.
17th Nov 2016, 5:31 PM
Franky BrainBox
Franky BrainBox - avatar
+ 1
when u create an object and if u did not create constructor then JRE make a default constructor itself.... and U create number of constructors and call with object .
17th Nov 2016, 6:51 PM
bikash panda
bikash panda - avatar
+ 1
as many as u want!
17th Nov 2016, 9:38 PM
ANT
+ 1
define as many as you want. Although Java provides a default constructor, good practice would dictate you always provide a constructor to initialize all attributes to a default value. This provides documentation to the code and leaves nothing to chance. Not initializing attributes can lead to errors.
1st Dec 2016, 1:52 PM
David Zimmer
David Zimmer - avatar
0
You can define no constructor. In this case, Java provides a default constructor with no parameter when you create an object(instance) of a class. You can define one or more than one constructor. In this case, The default constructor that Java provides will not be used. And the constructor that you created will be used when you create an object(instance) of a class.
18th Nov 2016, 1:46 AM
The PGDeveloper
The PGDeveloper - avatar