• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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

 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

     
    Ranch Hand
    Posts: 317
    Eclipse IDE
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The Logic is run time polymorphism.
     
    Ranch Hand
    Posts: 774
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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,
     
    Sandra Bachan
    Ranch Hand
    Posts: 434
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I appreciate the clarifications, thank you all
    reply
      Bookmark Topic Watch Topic
    • New Topic