0

Static

can anyone explain static. static int.

31st Dec 2016, 1:03 AM
Juan Madrigal
Juan Madrigal - avatar
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).
31st Dec 2016, 5:38 AM
Ivan G
Ivan G - avatar
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.
1st Jan 2017, 12:49 AM
Pascal Benstrong
Pascal Benstrong - avatar