Could someone please explain why are attributes of a class are not ordinarily defined to be static.
Could someone please explain why are attributes of a class are not ordinarily defined
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When a field is made static, it is associated with that class. It means that once initialized, every use of the field sees that same thing. Take a look:
This would be used as
Test.test. You can think of it as a field of theClassobject that is created on loadingTest.When you make a field non-static, that means it is associated with an instance of the class. So if you had this:
… you’d use it like so:
It could vary from instance to instance, for example if the
testfield is initialized through a constructor argument or altered via a method.