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?
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
posted
0
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!)