As I can understand here 'a1' reffed to a class B object which has 'a=200' as an attribute. Therefore I expected program will print 200. But why does this program prints 100 instead of 200?
class A{
int a=100;
}
class B extends A{
int a=200;
}
class Demo{
public static void main(String args[]){
A a1=new B();
System.out.println("a : "+a1.a); //Prints 100
}
}