aspose file tools*
The moose likes Beginning Java and the fly likes overloading + inheritance + widening Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "overloading + inheritance + widening" Watch "overloading + inheritance + widening" New topic
Author

overloading + inheritance + widening

Akila Sathyan
Greenhorn

Joined: Oct 03, 2008
Posts: 2
Hi,
came across this code in a mock exam.
----------------



-----------
Since the parameter to the method "scale()" was '1' - an int literal, I assumed that the method in the Circle class will be invoked. But the method in the base class Shape gets invoked. Can someone please explain?

[edit]Add code tags. CR[/edit]
[ October 04, 2008: Message edited by: Campbell Ritchie ]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

came across this code in a mock exam.


Also... Please Quote Your Sources.

Thanks,
Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Since the parameter to the method "scale()" was '1' - an int literal, I assumed that the method in the Circle class will be invoked. But the method in the base class Shape gets invoked. Can someone please explain?


The reference type is of Shape. The method (signature of) that it will call -- including which overloaded method, is determined at compile time, using the reference type. Based on the reference, there is only one scale() method, which takes a long, hence, that is the method that is called.

Henry
[ October 04, 2008: Message edited by: Henry Wong ]
Akila Sathyan
Greenhorn

Joined: Oct 03, 2008
Posts: 2
Sorry about the protocol goof-ups. I've updated my profile (I did have to give up a little bit of my culture - I'm from I-only-got-one-name culture!)

Here is the mock exam link:
http://www.irixtech.com/category/java/scjp-quiz
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: overloading + inheritance + widening