Site icon DataFlair

Java Static Variable, Method, Object with Examples

Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java

Program 1

class Abc
{
      static int count=0;
        static
        {
            System.out.println("This is static block");
        }
      Abc()
      {
         System.out.println("This is constructor");
           count++;
      } 
      static void display()
      {
             System.out.println(count);
       
      }
}
class TestStatic 
{
    public static void main(String args[])
    {
          System.out.println("Hello");
            // Abc.display();
            // Abc A1=new Abc();
            // Abc A2=new Abc();
            // Abc A3=new Abc();
            // Abc A4=new Abc();
            // Abc A5=new Abc();
    }
}

 

Exit mobile version