June 9, 2002 - Implementing Interfaces | WebReference

June 9, 2002 - Implementing Interfaces

Yehuda Shiran June 9, 2002
Multiple Inheritance of Interfaces
Tips: June 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Let's implement the following two interfaces:

  interface FirstInter{
    function printSomething();
  interface SecondInter{
    function printSomething();
by the myClass class. It implements both of these interfaces, providing the body of the printSomething() function:

  class myClass implements FirstInter, SecondInter {
    function printSomething() {
      print("This is something else");
Let's create a new instance of myClass:

  var demo : myClass = new myClass();
Let's define two variables as having the types of the interfaces above, and assign them the demo instance above:

var inter1 : FirstInter = demo;
var inter2 : SecondInter = demo;
Now all three variables (demo, inter1, inter2) share the same implementation of printSomething(), because they all reference the same instance, demo. The following code:

yields three identical lines:

  This is something else
  This is something else
  This is something else
To learn more about JScript .NET, go to Column 110, JScript .NET, Part IV: Inheritance.