0

Any good meaning of static and its uses?

9th Aug 2018, 3:32 AM
Prince Verma
Prince Verma - avatar
2 Réponses
9th Aug 2018, 11:01 AM
Eduardo Petry
Eduardo Petry - avatar
+ 2
static is a keyword in java which specifies that the member of a class (the member being declared static) is a single copy for all instances of a class. Like normal members, it is not made into separate copies for separate objects of a class. example code class A{ static int num = 0; } class B{ A h1 = new A(); A h2 = new A(); public static void main (String[] args){ h1.num += 1; h2.num += 1; System.out.println(h1.a); // will print 2 } }
9th Aug 2018, 4:01 AM
Vedant Bang
Vedant Bang - avatar