Consider the int a variables in these classes:
int a
class Foo { public int a = 3; public void addFive() { a += 5; System.out.print(\"f \"); }
Here F is of type Foo and f variable is holding Bar object but java runtime gets the f.a from the class Foo.This is because in Java variable names are resolved using the reference type and not the object which it is referring.