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:
{
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