Can i have a static constructor and a regular constructor in the same class? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can i have a static constructor and a regular constructor in the same class?

2nd Jan 2017, 8:23 AM
Anonymous Beast
Anonymous Beast - avatar
4 Answers
+ 2
Although you don't really add the static keyword, constructors already are, and can only be static. Think about it, a constructor is something you call BEFORE having a class instance.
2nd Jan 2017, 9:47 AM
Dao
Dao - avatar
+ 1
Why would you need to initialize a STATIC variable for each instance? I think you should consider making it not static.
2nd Jan 2017, 7:40 PM
Dao
Dao - avatar
0
but you can't initialize static variables that way.
2nd Jan 2017, 3:25 PM
Anonymous Beast
Anonymous Beast - avatar
0
yes, you're right. if i really needed to initialize static variables i could use a static method. thanks for the answers.
3rd Jan 2017, 8:08 AM
Anonymous Beast
Anonymous Beast - avatar