Sealed classes and methods: Difference between revisions

Created Nim solution.
(J)
(Created Nim solution.)
Line 79:
 
J does not provide a mechanism to seal individual methods.
 
=={{header|Nim}}==
Nim allows to define object types. There is two ways to make a type inheritable. Here is an example:
 
<syntaxhighlight lang="Nim">type T1 = object # Non inheritable.
type T2 = object of RootObj # Inherits from Root and is inheritable.
type T3 {.inheritable.} = object # New object root which is inheritable.
 
type T4 = object of T2 # Inheritable.
type T5 = object of T3 # Inheritable.
type T6 {.final.} = object of T2 # Non inheritable.
</syntaxhighlight>
 
As we can see in the example, if a type inherits from another type, it is also inheritable unless it is annotated with the <code>final</code> pragma.
 
In Nim, one can define methods on objects. There is no way to declare a method as final to forbid its overriding.
 
=={{header|Phix}}==
256

edits