[Advanced-java] OOP's Question

Don Bate don.bate at bateconsulting.com
Fri Apr 27 12:14:47 PDT 2007


Conceptually, there's a dispatch table that is part of the object 
instance and this table is constructed at object creation time. It's 
is used to determine which implementation of a method to invoke. By 
default, invocations go against the most extended implementation but 
that default can be altered only by using super in Java. Class B has 
visibility to Class C's methodA's signature but not it's 
implementation so it's going to actually invoke whichever 
implemention is in the instance's dispatch table.

Hope this helps.

Don

At 9:42 AM -0700 4/27/07, Brian Mulanda wrote:
>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
>_______________________________________________
>Advanced-java mailing list
>Advanced-java at lists.XCF.Berkeley.EDU
>https://lists.XCF.Berkeley.EDU/mailman/listinfo/advanced-java


-- 
Don Bate               | Specializing in Consulting and Mentoring in
Bate Consulting, Inc   | Object-Oriented Technologies,
                        | Software Architecture, and Software Process
(972) 618-0208 voice
(972) 618-0216 fax
don.bate at bateconsulting.com



More information about the Advanced-java mailing list