|
June 29, 2002 Implementing the Integer Version of the ICopyObj Interface Tips: June 2002
Yehuda Shiran, Ph.D.
|
|
One of the ways to support polymorphism is to define an interface that accepts an object of the type Object, and implement it in classes that support actual types as integer, double, and user-defined classes. The code below defines the interface ICopyObj which is implemented by the class CopyInt. This class defines two methods: the constructor CopyInt() and the interface function Copy(). The main program creates two variables, h1 and h2. The variable h1 is generated through the CopyInt() constructor. The variable h2 is generated through the Copy() operator. We print both variables at the end. Here is the code listing:
And here is the Command Prompt window, showing the code again (interface.js), the jsc compiler's log messages, and the output of interface.exe:
People who read this tip also read these tips: Look for similar tips by subject: |