Hi sricharan,
Originally posted by Sricharan Modali:
Hi
I thought the output for this program would be 10 but it is 20.
Can anyone please explain me the reason.
Thanks!
Sricharan
Here during the runtime, for the call: a.hi(a.i), a.hi refers to the method definition in the Trial class(a is an instance of the Trial class) and a.i refers to the variable in the class A (as a is of class A type). But in the method definition of the hi in the Trial class, you are printing the local variable i and not the argument passed. The value of the local variable i is 20 and so it prints 20.
Hope this helps
bye.
sk