0

a simple example of static VARIABLE

public class Soldier{ public static int numSol=0; Soldier(){ numSol++; } Soldier(int num){ numSol += num; } } public class MyClass { public static void main(String[ ] args) { Soldier snip1 = new Soldier(); Soldier snip2 = new Soldier(); Soldier comander = new Soldier(2); System.out.println(Soldier.numSol); } }

8th Jul 2017, 11:54 AM
Hari krishna
Hari krishna - avatar
1 Resposta
0
it will print 4.
8th Jul 2017, 8:43 PM
ussefshahid
ussefshahid - avatar