Monday, December 5, 2016

Write a JAVA program to demonstrate static variables, methods, and blocks.

 Aim: Write a JAVA program to demonstrate static variables, methods, and blocks.

Program:


class UseStatic 
{
  static int a = 3;
  static int b;
   
  static void meth(int x) 
  {
    System.out.println("x = " + x);
    System.out.println("a = " + a);
    System.out.println("b = " + b);
  
  }
  static 
  {
    System.out.println("Static block initialized.");
    b = a * 4;
  }
  
  
  public static void main(String args[])
  {
    meth(42);
    meth(4);
    meth(0);
  }
}

Output:



Labels:

1 Comments:

At February 15, 2018 at 6:57 AM , Anonymous Anonymous said...

thanku very much madam

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home