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 Java Objects (Retired) Harnessing the Power of Objects Methods and Constants

Philip Schultz
Philip Schultz
11,437 Points

Static?

Can someone please explain to me what the static type did. Was it used just for the purpose to access it easier through repl? Also, I don't understand what repl is doing, would someone please explain it to me in layman terms?

3 Answers

Mike Atkinson
Mike Atkinson
6,882 Points

Remember that the class is like the blueprint to create the objects with. So by declaring a variable static, it means you can access that variable before you even make an object. As in, you are reading the variable straight off the blueprints.

As for repl, normally (without repl) you compile your source code and then run at all at the same time. With repl you can run it line by line, or just type in the code line by line as you go.

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hey Philip,

A static variable is one that's associated with a class, not objects of that class. You can create a class with a static variable

public class Cool {
   public static String coolStaticVariable = "I'm a static variable of this very cool class "Cool"";
}

Somewhere in your programm inside your main method, you can call this "static" variable without creating a new object.

public class Application {

   public static void main(String[] args) {
       System.out.println (Cool.coolStaticVariable);
    }

}

I hope it helps

Please more explanation on:

  • static -private -public -object -class

couple examples on the different ways these things work?