Can constructor be public, private, protected | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can constructor be public, private, protected

?

12th Sep 2017, 6:11 AM
V V
4 Answers
0
class classname{ public classname(){ // these constructor must public } // same with the class name // it will executed once during first load // during classname a = new classname(); }
12th Sep 2017, 6:51 AM
Mikhael Anthony
Mikhael Anthony - avatar
0
I wouldn't recommend making it private as it needs to be called from outside the class.
12th Sep 2017, 10:56 AM
josh mizzi
josh mizzi - avatar
0
The only way I can think a private constructor could be used is Class a{ private a() { } Public static void main(String[] args) { New a(); } }
12th Sep 2017, 3:17 PM
josh mizzi
josh mizzi - avatar
0
Thanks
12th Sep 2017, 3:59 PM
josh mizzi
josh mizzi - avatar