Monday, June 25, 2018

WAP IN JAVA TO SHOW THE USE OF STATIC VARIABLE

class StaticVar
{
    static int count;
    public void inc()
    {
        count++;
    }
}
class Sixteen{
    public static void main(String args[])
    {
        StaticVar obj1=new StaticVar();
        StaticVar obj2=new StaticVar();
        obj1.inc();
        obj2.inc();
        System.out.println("count: "+StaticVar.count);
        System.out.println("count: "+StaticVar.count);
    }
 
}



No comments:

Post a Comment