This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Posted by saddy on January 22, 2001 at 12:15 PM
Here is a short program
int i = 10;
System.out.println(" i am in A");
class B extends A
int i =20;
System.out.println(" i am in B ");
public static void main(String args)
A a = new B();
System.out.println(" i = "+a.i);
on executing the above program the output is:
i = 10
i am in B
that is object a is pointing instance variable of A where as invoking methods from class B although instance variable with the same name i.e. i(here) is present in the base class .
can anybody please help me why it is behaving like this.
Thanx in advance
- Still confused ??? Kishori Sharan January 22, 2001 at 1:14 PM
- When? Ivan Villanueva January 23, 2001 at 11:05 AM
- RE:When? Kishori Sharan January 23, 2001 at 12:53 PM
- Sorry? Calahans January 24, 2001 at 6:54 AM