class staticandnonstatic
{
int a=100;
static int b=200;
void funa()
{
int a=10;
System.out.println("\nnon static variable a :"+a);
System.out.println("\nstatic variable b :"+b);
}
static void funb()
{
//System.out.println("\na :"+a);
System.out.println("\nstatic variable b :"+b);
}
public static void main(String args[])
{
//System.out.println("\nnon static variable a :"+a);
System.out.println("\nstatic variable b :"+b);
staticandnonstatic san= new staticandnonstatic();
//funa();
san.funa();
System.out.println("\nnon static variable a :"+san.a);
san.funb();
funb();
}
}
===================================================
observe the comment lines.
that lines are errors.
so, not use like that
===================================================
output :
static variable b :200
non static variable a :10
static variable b :200
non static variable a :100
static variable b :200
static variable b :200
{
int a=100;
static int b=200;
void funa()
{
int a=10;
System.out.println("\nnon static variable a :"+a);
System.out.println("\nstatic variable b :"+b);
}
static void funb()
{
//System.out.println("\na :"+a);
System.out.println("\nstatic variable b :"+b);
}
public static void main(String args[])
{
//System.out.println("\nnon static variable a :"+a);
System.out.println("\nstatic variable b :"+b);
staticandnonstatic san= new staticandnonstatic();
//funa();
san.funa();
System.out.println("\nnon static variable a :"+san.a);
san.funb();
funb();
}
}
===================================================
observe the comment lines.
that lines are errors.
so, not use like that
===================================================
output :
static variable b :200
non static variable a :10
static variable b :200
non static variable a :100
static variable b :200
static variable b :200