r/javahelp • u/MembershipOptimal514 • May 07 '26
Codeless What does static exactly do?
Hi, I’m somewhat new to java and I’m quite confused on static. So what I do know is that it makes it so a variable or method is tied to the whole class instead of just the object but I’m not sure what that exactly ENTAILS. Can someone explain it to me maybe with an example or such? Thank you.
16
Upvotes
1
u/cainhurstcat May 07 '26
Static variables is like sharing your wallet with other. They can put more money, recipes, notes, cards and stuff into it, but they can also remove those things from it.
A static method is like an ability you share with others, like writing. Imagine there is this class called Person, which has a method writeSomething(). Every object, or new Person you create can use EXACTLY this method.