onion&&remote-control — static binding

Runtime binding is covered in a few posts with onion and remote-control. Now let’s apply our analogies to static method binding. P 45 [[ java precisely ]] has a good example 59.

C2 c2 = new C2(); // C2 extends C1 and hides a static method C1.m1() with C2.m1()
C1 c1 = c2;

Now c1 and c2 are 2 remote controls programmed for a single onion, the “biggest onion” [1]. However,
* variable c1 is a remote control of type C1 and supports C1.java’s static m1() only
* variable c2 supports C2.java’s static m1() only.

Now the question:
Q: how are the various calls to m1() resolved.
A: C1.m1() and C2.m1() are obvious.
A: c1.m1() binds to C1.java static m1(). The onion, which happens to be a C2 onion, doesn’t affect the resolution.
A: c2.m1() binds to C2.m1()

[1] Therefore instance methods c1.m1(int) and c2.m1(int) {c1 c2 both lower-case} are both bound to C2.java m1(int). Runtime binding of instance method m1(int).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s