erg/examples/class.er
Shunsuke Shibayama a6876f10d0 Update class.er
2022-09-07 21:56:33 +09:00

14 lines
347 B
Python

@Inheritable
Point2D = Class {x = Int; y = Int}
Point2D.
norm ref self = self::x**2 + self::y**2
Point3D = Inherit Point2D, Additional := {z = Int}
Point3D.
@Override
new x, y, z = Point3D::__new__ {x; y; z}
@Override
norm ref self = self::x**2 + self::y**2 + self::z**2
p = Point3D.new {x = 1; y = 2; z = 3}
print! p.norm()