mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 20:14:45 +00:00
25 lines
743 B
Python
25 lines
743 B
Python
# Inheritance is prohibited by default. Remove this decorator and check for errors.
|
|
@Inheritable
|
|
Point2D = Class {x = Int; y = Int}
|
|
Point2D::
|
|
one = 1
|
|
Point2D.
|
|
zero = Point2D::one - 1
|
|
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
|
|
|
|
# `Point2D::__new__` is private, use `Point2D.new` instead
|
|
p = Point2D.new {x = 1; y = 2}
|
|
print! p, p.norm()
|
|
print! Point2D.zero
|
|
# print! Point2D::one # cannot access private variables
|
|
q = Point3D.new 1, 2, 3
|
|
print! q, q.norm()
|