My code is:
class Foo {
public int a=3;
public void addFive() {
a+=5;
System.out.print(\"f \");
}
}
class Bar extends Foo {
public int a=8;
F
is a reference of type Foo
, and variables aren't polymorphic so f.a
refers to the variable from Foo
which is 3
How to verify it?
To test this you can remove a
variable from Foo
, it will give you compile time error
Note: Make member variable private
and use accessors to access them
Also See