Pages

Saturday 14 December 2019

Program on Instance ,Static ,Local variables

public class Variables
{
   int a=10; // INSTANCE VARIABLE
   static int c=30; // STATIC VARIABLE
   public static void main(String[] args)
     {
    int b=20; // LOCAL VARIABLE

    Variables v= new Variables();// object creation is required to access instance variable
    int z=v.a;

    System.out.print("\n INSTANCE VARIABLE ="+v.a);
    System.out.print("\n LOCAL VARIABLE ="+b);
    System.out.println("\n STATIC VARIABLE ="+c);

    System.out.print("\n INSTANCE VARIABLE ="+z+ "\n" +" LOCAL VARIABLE="+b+ "\n" +" STATIC VARIABLE = "+c);

     }
}

output:
 

No comments:

Post a Comment

Constructors & Destructors in c++

  Constructors :  A Constructor is a special member function, which is used to initialize the objects of its class. The Constructor is invok...