Second method, for environment supporting object-oriented programming, application can create an instance of entity class object of other language as talking about previously. The instance can be accessed by the two languages simultaneously. This method is more flexible. Application can create overloading functions of class object to support callback. For examples, if an object with function “Add” is defined in python language, application in java can create an instance of it and overloading the function “Add”. Then, python can callback to java through the “Add” function.
In above figure, python class object defines two functions “Add” and “Dec”. The “Add” function is overridden by java instance. The instance is managed by environment, and is visible to java and python. Python can call “Add” function of java instance to perform callback function. For “Dec” function, because instance does not override this function, the call will be redirected to class object of python.