mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 02:39:20 +00:00
15 lines
427 B
Python
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()
|