private

Summary

The private keyword modifies access. The private access level is the least permissive. If a member is declared private, it can only be accessed from within the class (including inner/nested classes) or module it was declared.

Syntax

private member

Parameters

member
The member to make 'private'.

Description

The private keyword is an access modifier. It is used to change the visibility and access privilege for a member to the least permissive level.

For classes, if a class member is declared private, it can only be accessed from within the class it was declared (including inner/nested classes).

For modules, if a module member is declared private, it can only be accessed from within the module it was declared.

Examples

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

See Also

Share

HTML | BBCode | Direct Link