Forums Register Login

What is the logic behind designing how Overloaded vs Overridden methods are invoked?

+Pie Number of slices to send: Send
Greetings,

I am studying for SCJP 6 Exam by reading

SCJP Sun® Certified Programmer for Java™ 6 Study Guide Exam (310-065)
By: Kathy Sierra; Bert Bates
Print ISBN-10: 0-071-59106-0


I am on Chapter 2, Overriding / Overloading (Exam Objectives 1.5 and 5.4). From what I understand, OVERLOADED methods are invoked based on the information received by compiler at compile time, while OVERRIDDEN methods are invoked based on information received by JVM at runtime. What is the LOGIC behind this design, why isn't it vice versa, i.e. OVERLOADED methods invoked at runtime, OVERRIDEN methods invoked based on information received by compiler.
+Pie Number of slices to send: Send
The compiler does not check for everything at the compile time only
means the checking is superficial and compiler does not know what will happen at run time
At compile time , the type of the object is checked and at the run time the object is checked
Remember :
  • Which overloaded method to be called is decided at the compile time
  • Which overriden method to be called is decided at the run time

  • To make things clearer
    you can take a look at the following code

    +Pie Number of slices to send: Send
    The Logic is run time polymorphism.
    +Pie Number of slices to send: Send
    Hello

    The choice of which overloaded method to call is made at compile time. Compiler looks at the reference type to decide which overloaded
    method to call.

    The choice of which overridden method to call is based on actual object type based at run-time. Polymorphism concept is applied here.

    Hope this helps,
    +Pie Number of slices to send: Send
    I appreciate the clarifications, thank you all
    Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com


    reply
    reply
    This thread has been viewed 829 times.
    Similar Threads
    K&B SCJP 5: Chapter 8, Self Test 9, wrong answer?
    Passed the SCJP 6 with 98%
    scjp 1.6
    SCJP Mock Exam Doubts
    Doubt in K&B SCJP 5: topic - Overriding
    More...

    All times above are in ranch (not your local) time.
    The current ranch time is
    Mar 19, 2024 01:30:51.