FAQ: Static Members - Static Constructors

This community-built FAQ covers the “Static Constructors” exercise from the lesson “Static Members”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn C#

FAQs on the exercise Static Constructors

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

in the exercise, we created static fields forestsCreated and treeFacts,
then we created static methods ForestsCreated and TreesFacts,
why in the static constructor we set values to forestsCreated (field) but the other to TreesFact(method)

While I was writing my question, I realized - because we do not have set() method in ForestCreated :))))
am I right? think, I am right :wink:

posting my msg in case if someone has the same question

Think you got the names switched but yeah.

But to me it looks like there is no real difference between having a setter or just defining the variable somewhere else. Except of course when u want to manipulate the variable, the name you use will be different( the upper casing). Do you think it’s right to think like this? Tell me your thoughts if you are just as intrigued.

Hi abel3047, Thank you for reacting on my post. I would be glad to speak to you but I am far away from this exercise, deep in JavaScript at the moment. You could be right, let see what other people will say. Happy Coding!

No problem! When and why did u start learning Java? And how has your coding learning experience been?

One thing I didn’t understand in this lesson was whether the static constructor is called once every time the class is mentioned (via static method or instantiation) or if it is called one time only in a program and never again. After researching it seems the latter is true.

I understand the static constructor as something that simply sets up the correct common (static) variables for the class.

Just thought this might be nice for people to know in case anyone else got confused. Also, if I’m wrong, please correct me. :slight_smile:


Yeah, I was struggling with the same thing. I now think a static constructor can run only once but I’m unsure, it would be a welcome addition to the lesson if it was mentioned.