[Advanced-java] OOP's Question
Brian Mulanda
bmulanda at yahoo.com
Fri Apr 27 09:42:34 PDT 2007
Jayprakash,
I understand why you question this behavior; it's not entirely obvious
which methodA() would be invoked. At first I thought it would be C's
methodA(). However, tests prove that it is A's methodA() that get's
invoked.
Now the question is why. Intuition suggests, it's because the chain of
method calls leading to the invocation of methodA() originated from A.
So the JVM looks for methodA() "bottom-up" with A at the bottom and C
at the top. This may not be the correct explanation.
So, it's worth investigating how method invocation works in such a case.
When you find out, please share with us your findings.
_____
Brian
--- "G.N.V. Jayprakash" <gnvjp at hotmail.com> wrote:
>
> Hi,
> I have a question in Object Oriented Programming:
>
> A extends B. B extends C. There is a public method methodA() implemented in C. methodA() is also
> overridden in A.
>
> There is a flow starting from A from preProcessRequest() implemented in A. preProcessRequest()
> is also implemented in B.
>
> Now preProcessRequest() in A invokes super.preProcessRequest(). The control goes to the
> preProcessRequest() in B.
> preProcessRequest() method implementation in B invokes methodA().
>
> Now the question is: Will the methodA() implemented in C will be invoked or the methodA()
> implemented in A will be invoked? Why?.
>
> Thanks & Regards,Jayprakash
> _________________________________________________________________
> News, entertainment and everything you care about at Live.com. Get it now!
> http://www.live.com/getstarted.aspx> _______________________________________________
> Advanced-java mailing list
> Advanced-java at lists.XCF.Berkeley.EDU
> https://lists.XCF.Berkeley.EDU/mailman/listinfo/advanced-java
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the Advanced-java
mailing list