Write a program to demonstrate the difference between static & non-static variables.

public class StaticTest
   {

             private int count=0;
             public static void main(String args[])
                {
        StaticTest a=new StaticTest();
 
                  
       a.count++; //compiler error: non-static variable count cannot be referenced from a static context
  System.out.print("ab="+count);              
 }
 

   }

No comments:

Post a Comment