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();
    }
}

 

Did you know we work 24x7 to provide you best tutorials
Please encourage us - write a review on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *