r/javahelp • • 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.

15 Upvotes

37 comments sorted by

View all comments

Show parent comment

2

u/SymbolicDom May 08 '26

A method is a function that implicity get a pointer to the object = this. An static method don't get that so it's an normal function.

If you write object oriented code in something like c you write something like

Struct Monster { String name Int speed Int x Int y }

Function monster_draw (Monster *monster) { DrawCircle(monster.x, monster.y) }

In an more object oriented language we can write the same thing a litle shorter.

Class Monster { String name Int speed Int x Int y

Draw() { drawCircle(this.x, this.y) } }