user
Definition

In object-oriented programming, a **sealed** or **final class** is one which cannot be inherited from.

Classes are sometimes made non-subclassable in this way if the author feels that it would not be useful or even undesirable for subclasses to be created from them. Moreover, in a compiled language, knowing that a class cannot be subclassed, may enable optimizations to be made.

Rather than sealing the entire class, it may be possible to just seal certain methods for the same reasons and with the same potential benefits.

Task

If your language supports the object oriented paradigm, explain what support it has for sealed classes and/or methods and, if there is no support, what if anything can be done to simulate them. If possible illustrate your answer with an example.

If your language does not support the object oriented paradigm (or its inheritance aspect), you may either simply say so, omit the task altogether or describe any equivalent structure(s) and restrictions on use which the language does have.

Reference

* Inheritance Non-subclassable classes

Related task

* Classes
* Inheritance/Single
* Inheritance/Multiple
assistant
Raku doesn't have final class but Roles is normally used to mimic the goal.

```
# 20240626 Raku programming solution

role MovieWatcherRole { has Str $.name;
   method WatchMovie() { say "$.name is watching the movie."   }
   method EatPopcorn() { say "$.name is enjoying the popcorn." }
}

class MovieWatcher does MovieWatcherRole {
   method new(Str $name) { self.bless(:$name) }
}

class ParentMovieWatcher is MovieWatcher { }

role ChildMovieWatcherRole {
   method EatPopcorn() { say "$.name is eating too much popcorn." }
}

class ChildMovieWatcher is MovieWatcher does ChildMovieWatcherRole { }

role YoungChildMovieWatcherRole {
   method WatchMovie() { 
      say "Sorry, $.name, you are too young to watch the movie." 
   }
}

class YoungChildMovieWatcher is ChildMovieWatcher does YoungChildMovieWatcherRole { }

for ParentMovieWatcher.new('Donald'),
    ChildMovieWatcher.new('Lisa'),
    YoungChildMovieWatcher.new('Fred')
{ .WatchMovie and .EatPopcorn }

```

You may Attempt This Online!