September 2017
Beginner
402 pages
9h 52m
English
As we have seen, a child class receives all the public methods that the base class defines. In some cases, this is not desired. Making the method private is also not always a solution, as you may want to call it on the object of the base class.
Perl 6 allows so-called submethods. They are not inherited. Let us learn about them in a small example:
class Parent { method meth() { say 'meth()'; } submethod submeth() { say 'submeth()'; }}class Child is Parent {}
Now, create two objects:
my $o1 = Parent.new;my $o2 = Child.new;
In the Parent class, there are two methods that can be called on the object of that type:
$o1.meth(); # meth()$o1.submeth(); # submeth()
In the Child class, only the meth method is available:
$o2.meth(); # ...Read now
Unlock full access