|Navigation: Language Reference > 5 - Declaration Attributes > Variable and Entity Attributes >====== PRIVATE (set variable private to a CLASS module) ======|
The PRIVATE attribute specifies that the variable on which it is placed is visible only to the PROCEDUREs defined within the source module containing the methods of the CLASS structure (whether members of the CLASS or not). This encapsulates the data from other CLASSes.
PRIVATE is also valid when used with static (threaded or non-threaded) variables outside of a CLASS structure. If a static variable is declared with the PRIVATE attribute, the compiler generates it without a public external name. Hence, it can only be used by procedures defined in the same source module.
The PRIVATE attribute is also allowed for TYPE declarations.
PublicVar LONG !Declare a Public variable
PrivateVar LONG,PRIVATE !Declare a Private variable
BaseProc PROCEDURE(REAL Parm)!Declare a Public method
TwoClass OneClass !Instance of OneClass
TwoClass.PublicVar = 1 !Legal assignment
TwoClass.PrivateVar = 1 !Illegal assignment
OneClass.BaseProc PROCEDURE(REAL Parm)
SELF.PrivateVar = Parm !Legal assignment
TwoClass.PrivateVar = 1 !Legal assignment