Through the following program, this challenge shows how a same member procedure ('Child.test()') can produce a different execution only depending on its calling way on a same object, either on Child-typed instance 'cc' (by static binding at compile-time), or on Parent-typed instance 'pc' (then dynamic binding at run-time).
Compile with fbc rev >= 1.04.0:
Code: Select all
Dim Shared As String s0
s0 = "Typename"
Type Parent Extends Object '' beginning of Parent type declaration
Declare Abstract Sub test (Byref s As String = s0)
End Type '' ending of Parent type declaration
Type Child Extends Parent '' beginning of Child type declaration
Declare Sub test (Byref s As String = s0)
End Type '' ending of Child type declaration
Sub Child.test (Byref s As String = s0)
Print "Calling Child.test() on a " & s & "-typed instance"
End Sub
Dim As Child c
Dim Byref As Child cc = c
Dim Byref As Parent pc = c
cc.test()
pc.test()
Sleep
Instead of:Calling Child.test() on a Child-typed instance
Calling Child.test() on a Parent-typed instance
Calling Child.test() on a Typename-typed instance
Calling Child.test() on a Typename-typed instance