Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

1 Answer

Brandon Khan
Brandon Khan
21,619 Points

Its the same across all instances of the class.

If you have a class with a static variable then make two instances of that class they will return the same value. Even if you only change it in one of the classes. An example they used was if you have 10 bad guys in a video game then they have a static int totalBads = 10. If you have a function that says if i get killed lower totalBads by 1. It will change totalBads in in every bad guy you have active. If you had a no static variable int hp = 10 and this value gets changed it will only get changed in the bad guy that had the change happen....

I hope this helped... here is some documentation too. https://www.javatpoint.com/static-keyword-in-java