erg/examples/class.er
2022-09-08 09:53:32 +09:00

15 lines
427 B
Python

@Inheritable
Point2D = Class {x = Int; y = Int}
Point2D.
norm self = self::x**2 + self::y**2
Point3D = Inherit Point2D, Additional := {z = Int}
Point3D.
# Overloading is prohibited by default. Remove this decorator and check for errors.
@Override
new x, y, z = Point3D::__new__ {x; y; z}
@Override
norm self = self::x**2 + self::y**2 + self::z**2
p = Point3D.new {x = 1; y = 2; z = 3}
print! p.norm()