protected

Summary

The protected keyword modifies access. If a member is declared protected, it can be accessed from within the class/module it was declared and from any subclasses or submodules.

Syntax

protected member

Parameters

member
The member to make 'protected'.

Description

The protected keyword is an access modifier. It is used to change the visibility and access privilege for a member.

For classes, if a class member is declared protected, it can be accessed from within the class it was declared and all subclasses, inner classes, and nested classes.

For modules, if a module member is declared protected, it can be accessed from within the module it was declared and all children/submodules.

Examples

Protected Field
1
2
3
4
class Foo
{
    protected int bar = 1;
}
Protected Method
1
2
3
4
5
6
7
class Foo
{
    protected int bar()
    {
        return 1;
    }
}
Protected Submodule
1
2
3
4
5
6
module Foo
{
    protected module Bar
    {
    }
}

See Also

Share

HTML | BBCode | Direct Link