I have this piece of code:
class Test {
public static void main (String[] args){
Base b1, b2;
b1= new Base(1);
b2= new Base(2);
System.out.println(b1.getX());
System.out.println(b2.getX());
}
}
public class Base {
static int x;
public Base(){
x=7;
}
public Base( int bM) {
x=bM;
}
public int getX() {
return x;
}
}
I was told that this program will return the values 2 and 2 but I cannot understand why. According to what I know it should show 1 and 2. Can someone explain or give a link to an explanation? Thank you.
static. This should help you out: download.oracle.com/javase/tutorial/java/javaOO/classvars.html