Advertisement
|
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
Artima Forums.
Message:
confused ????
Posted by saddy on January 22, 2001 at 12:15 PM
Here is a short program class A { int i = 10; void meth() { System.out.println(" i am in A"); } } class B extends A { int i =20; void meth() { System.out.println(" i am in B "); } public static void main(String args[]) { A a = new B(); System.out.println(" i = "+a.i); a.meth(); } }
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
Replies:
- Still confused ??? Kishori Sharan January 22, 2001 at 1:14 PM
(6)
- When? Ivan Villanueva January 23, 2001 at 11:05 AM
(5)
- RE:When? Kishori Sharan January 23, 2001 at 12:53 PM
(4)
- Sorry? Calahans January 24, 2001 at 6:54 AM
(3)
|