Himanshu Goel

Greenhorn
+ Follow
since Feb 20, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Himanshu Goel

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