Originally posted by Doit:
Hi Sanjay,
I do not agree with your statement.(No offense please!!)
After a1= a statement both the references are set to the
object created by using new B(). So i think both a,a1 of them
should look at methods in the subclass object.
ex: had it been
A a1= new B();
a1.giveBirth() should have used the code in sub class
Am i right?
So i too am confused here....Experts please guide ...
Originally posted by daryl o:
Oops, I meant to say:
Just because the arguments to giveBirth are related via a superclass/subclass relationship does not change that fact that B's versionOVERLOADS
A's.
AM<BR> <A HREF="mailto:[email protected]" rel="nofollow">[email protected]</A>
sona<br />SCJP
sona<br />SCJP
"JavaRanch, where the deer and the Certified play" - David O'Meara
Originally posted by parasu:
Hi all,
In the below example, i thought the answer was "Y". But when i executed i got "X". Could someone explain this?
class A
{
public A(){};
void giveBirth(A a)
{System.out.println("X");
}
}
class B extends A
{
public B(){}
void giveBirth(B b)
{System.out.println("Y");
}
public static void main(String args[])
{
B a = newB();
A a1 = new A();
a1 = a;
a1.giveBirth(a);
}
}
Thanks,
Parasu.