See it's a pure OO funda. You have created an object of Class B.Now every time you call the overridden method f() using this object reference the method in Class B will be called and not that from A.
Originally posted by Monika Pasricha:
class A {
int a = f();
int f()
{
return 1;
}
}
class B extends A
{
int b = a;
int f()
{
return 2;
}
}
public class CtorDemo1
{
public static void main(String args[])
{
B bobj = new B();
System.out.println(bobj.b);
}
}
The output is 2. I think it should be 1. acn anybody help me in this.
Thanx
Monika