hi, this is how your codes goes ?
-- As you can see st is the first reference variable of class StatInstance.
and the st.x is a static var= 16
-- so whenever you ask x value you get 16.
-- unless and untill you changed the value of x i.e x=34 --------- local var to method disp()
-- then when you ask x value ------------> we get 34
------ show() method is a static method
-------- z is a static var so -------> z = 35
--------- sto is another reference instance variable of class StatInstance with sto.x= 123
-> simple when you called sto.x we get >>>>>>>>>>>>123
-------lets see show1() method
sto.x = 123
- whenever you ask for x value ----------------> 123
in show method last line sto.x-------------> 123
------ as show1 method returns z value
------- z -----------> 120
-----------> in main method when we say st.x------------------> 34
----------- can you interpret from above result: ?
public class StatInstance {
int x=10;
static int z=20;
public void disp(){
z=35;
StatInstance st1=new StatInstance();
System.out.println(x+"here"); ------------>16
st1.x=40;
System.out.println(x+"heresecond"); ------------->16
StatInstance st0=new StatInstance();
x=34;
System.out.println(x+"herethird"); ------------>34
st0.x=89;
System.out.println(x); -------------->34
}
public static void show(){
System.out.println(z); ----------------------> z =35
z=100;
StatInstance st0=new StatInstance();
st0.x=123;
System.out.println(st0.x); ------------> 123
st0.show1();
System.out.println("x is "+st0.x); -----------------> x = 98
}
void show1(){
System.out.println(x); ------------->123
x=98;
z=120;
return;
}
public static void main(
String[] args){
StatInstance st=new StatInstance();
Integer i=new Integer(100);
Integer i5=new Integer(200);
System.out.println(i*i5); ------------------> 20000
st.x=16;
System.out.println(st.x); ------------------->16
st.disp();
st.show();
System.out.println(z); ------------------------->120
System.out.println(st.x); --------------------->34
}
}