Which instance method will be called depends on the actual class of the object and not the class of the variable referencing it. Here, the actual object is of class C. But this happens only when the method is inherited accross the hierarchy. Here, in class B, f() is private and so is not inherited by class C. So, when method g() of class B calls f(), class B's f() is called instead of class C's. HTH, Paul.
Private method calls are statically bound. A method will call the private method in the class where it is defined even if the calling method is inherited by a derived class and the derived class defines a method with the same signature as the private method. Since ref2 is cast to a B the private f() method of B is called not the f() in C. This information is from a certification notes page by cdesboro that was out on geocities but has apparently moved. Does anyone know where these notes can be found on the web? They helped me greatly in passing the SCJPtest. John
The only reason for time is so that everything doesn't happen all at once.
- Buckaroo Banzai