Originally posted by amod gole:
hi all,
i have one problem..
first see this code
class A
{
int i=10;
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
class B extends A
{
int i=20;
public static void main(String[] args)
{
A o1=new B();
System.out.println("Hello World!"+o1.i);
}
}
when i am pritning value of i it is giving me 10
can any one help me
Instance variables in a subclass do not override instance variables in the superclass with the same name, they hide them.
If you have an object of type B that is referred to with a reference of type A, then if you access the instance variable with that reference, you will get the value of the variable in A.