paxScript Demo. Classes and Inheritance. Namespace "Shapes".


paxBasic

Namespace Shapes
  Class Point
    Dim X, Y
    Sub New (X, Y)
      Me.X = X
      Me.Y = Y
    End Sub
  End Class

  Class Circle
    Inherits Point
    Dim R
    Sub New(X, Y, R)
      MyBase.New(X, Y)
      Me.R = R
    End Sub
  End Class
End Namespace

Dim P = New Shapes.Point(3, 5), C = New Shapes.Circle(3, 5, 7)
print P, C

paxC

namespace Shapes {
  class Point {
    var x, y;
    function Point(x, y){
      this.x = x;
      this.y = y;
    }
  }

  class Circle: Point {
    var
      r;
    function Circle(x, y, r): base(x, y) {
      this.r = r;
    }
  }
} // namespace

var
  P = new Shapes.Point(2, 3), C = new Shapes.Circle(3, 5, 7);
print P, C;

paxPascal

namespace Shapes
  class TPoint
    var X, Y;
    constructor Create(X, Y);
    begin
      Self.X := X;
      Self.Y := Y;
    end;
  end;

  class TCircle(TPoint)
    var R;
    constructor Create(X, Y, R);
    begin
      inherited Create(X, Y);
      Self.R := R;
    end;
  end;
end;

var
  Point = Shapes.TPoint.Create(3, 5), Circle = Shapes.TCircle.Create(3, 5, 7);
print Point, Circle;


Copyright © 1999-2006 VIRT Laboratory. All rights reserved.