I'm confused because I thought this referred to the current object calling on the method.
So why didn't the instance variable x in my object not get changed when calling on an inherited method?
Superclass:
public class SuperBoss
{
int x = 50;
public void changeX()
{
this.x = 20;
}
}
Subclass:
public class Boss extends SuperBoss
{
int x = 10;
public static void main(String[] args)
{
Boss b = new Boss();
b.changeX();
System.out.println(b.x); //prints 10
}
}
Why does it print 10 and not 20?