public

Summary

The public keyword modifies access. The public access level is the most permissive. If a member is declared public, it has no restrictions on access.

Syntax

public member

Parameters

member
The member to make 'public'.

Description

The public keyword is an access modifier. It is used to change the visibility and access privilege for a member to the most permissive level, which has no restrictions on access.

For class members, all other classes can access the member; the current class can access the member; subclasses, inner classes, and nested classes can access the member; and, finally, the member can be accessed from instances of the class without restriction.

For module members, all other modules can access the member, the current module can access the member, and all children can access the member.

Examples

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

See Also

Share

HTML | BBCode | Direct Link