This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt in overloading 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 "doubt in overloading " Watch "doubt in overloading " New topic
Author

doubt in overloading

Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531


now here at compile time wont the parent string be selected based on the Parent reference? why is the output then "child"
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18878
    
  40


First, this example is not overloading, it's overridding...

Ankur kothari wrote:
now here at compile time wont the parent string be selected based on the Parent reference? why is the output then "child"


Yes, the string is referenced at compile time. So, the Parent class' say() method will reference the Parent string. And the Child class' say() method will reference the Child string... both determined at compile time.

In your main method, you are not referencing any string. You are calling the say() method, which is resolved at runtime.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
ok.....got you....i have one more doubt

what is Number here in get() method...what kind of return is this? still the program compiles

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18878
    
  40

Ankur kothari wrote:
what is Number here in get() method...what kind of return is this?


java.lang.Number

Henry
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
Number is super type of Integer,Sort.....


SCJP 6,SCWCD 5,SCBCD 5

Failure is not an option.
Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1106
    
    1

Having Integer and Number as return type is an example of covariant return.

Oracle Java Web Service Developer (1z0-897), Oracle certified Java 7 Programmer, SCJA 1.0, SCJP 5.0, SCWCD 5.0, Oracle SQL Fundamentals I
 
GeeCON Prague 2014
 
subject: doubt in overloading