I have scenario like this
public class Test{
static int a;
int b;
public static void main(String[] args){
Test t1 = new Test();
Test t2 = new Test();
}
}
What will be the variables in object t1 and object t2?
As per my understanding since variable a is a static variable it will be both in object 1 and object 2.
And b will be created separate copy for both the objects.
But when I assign a value to variable b ie(int b=1) and call it like System.out.println(t1.b), System.out.println(t2.b)
Instead of getting an error I am getting 1 as output from both the objects.
Why is that?