0
Static
can anyone explain static. static int.
2 Réponses
0
Static variables are shared between all class instances (when you change it in one instance, it will change in every other instance of same class).
0
basically a static variable can be accessed without the need to create an instance of a class and like Ivan G said are shared between all class insurances
eg:
public class my Class
{
public static my Class me;
private String name;
public myClass (String name)
{
me = this;
this.name =name;
}
public String getName ()
{return this.name;
}
}
public class main
{
myClass a = new myClass ("John");
System.out.println (myClass.me.getName ());
}
// output
// John
in the example above I am able to access the getName getter through the static me variable.