aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes What is the logic behind designing how Overloaded vs Overridden methods are invoked? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "What is the logic behind designing how Overloaded vs Overridden methods are invoked?" Watch "What is the logic behind designing how Overloaded vs Overridden methods are invoked?" New topic
Author

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

Sandra Bachan
Ranch Hand

Joined: Feb 18, 2010
Posts: 434
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.

Marriage Made in Heaven
http://www.youtube.com/user/RohitWaliaWedsSonia
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 440

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


    SCJP 6 [86%] June 30th, 2010
    OCPWCD [84%] March 26th, 2012
    OCEJPAD [83%] September 6th, 2014
    If you find any post useful, click the "plus one" sign on the right
    Harpreet Singh janda
    Ranch Hand

    Joined: Jan 14, 2010
    Posts: 317

    The Logic is run time polymorphism.
    Prithvi Sehgal
    Ranch Hand

    Joined: Oct 13, 2009
    Posts: 774
    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,


    Prithvi,
    My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
    Sandra Bachan
    Ranch Hand

    Joined: Feb 18, 2010
    Posts: 434
    I appreciate the clarifications, thank you all
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: What is the logic behind designing how Overloaded vs Overridden methods are invoked?