You can read this to understand scope of variables or method .
In short -:
- public
public
- Any member of a class declared as public can be accessed outside of the class. So declare public when you want to give client code access to methods/variables of a class. - private
private
- A private method or field is invisible and inaccessible to other classes, and can be used only within the class in which the field or method is declared. - protected
protected
- Protected variables and methods allow the class itself to access them, classes inside of the same package to access them, and subclasses of that class to access them. - static
static
- In general when a number of objects created from the same class, they all have their distinct copies of instance variables stored in different location. Sometimes we want to have variables that are common to all objects. To accomplish this use static. Read this.
Think of the main
method as a place where you can write code to test your class. None ofNo design / logic should be placed in mainmain
.
For example -:
public class Hilo {
public Hilo() {}
//other methods...
public static void main(String[] args) {
Hilo hilo = new Hilo();
hilo.getRange();
hilo.playGame();
}
}
I would prefer to remove all the staticstatic
variables used in your class and make those as privateprivate
. The two methods getRangegetRange
and playGameplayGame
can be publicpublic
.