Ok, off the bat, I know this question either sounds like common sense, or very confusing due to its wording. Unfortunately, due to my lack of knowledge even after much research, I am unsure how to phrase it. To my understanding at this point, static variables do not refer to an instance of a class, and a class.method call is used to access them. variables declared non-static and public are instances of the class and can be called using an object.method call. However, in recent examples, I have seen statements such as:
private static Rectangle rect;
why not just write
public Rectangle rect;
How is this possible? I thought that static variables were not associated with instances of classes? I am just very confused regarding the meaning and limitations/usages of static versus non-static. I apologize for any confusion. If this question deems unanswerable, a link providing an example of SIMPLE differentiation between static and public usage would be greatly appreciated. I am a complete beginner so please avoid using too much technical jargon. Thanks in advance.
public/protected/private have nothing to do with static.
static means a member (be it a data member or a method) belongs to the class, and not to a specific instance.
public/protected/private just control what other classes can access these members, be it instance members or static members.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With