# Import <Foundation/Foundation. h>
@ Interface person: nsobject
{
Int _ age; // The default value of the variable in @ interface is @ public.
@ Protected
Int _ height; // It can only be accessed in the object methods of the current class and subclass.
@ Pritate
Int _ weight; // can be accessed directly only in the object method of the current class
@ Package
Nsstring * _ name; // it can only be used within the current framework
}
-(INT) age;
-(Void) setage :( INT) age;
-(INT) height;
-(Void) setheight :( INT) height;
-(INT) weight;
-(Void) setweight :( INT) weight;
-(Nsstring *) Name;
-(Void) setname :( nsstring *) Name;
@ End
@ Implementation person
{
Nsstring * birthday; // The default value of the variable in @ implementation is @ private.
}
-(INT) Age
{
Return-age
}
-(Void) setage :( INT) Age
{
-Age = age;
}
-(INT) Height
{
Return _ height;
}
-(Void) setheight :( INT) Height
{
-Height = height;
}
-(INT) Weight
{
Return _ weight;
}
-(Void) setweight :( INT) Weight
{
_ Weight = weight;
}
-(Nsstring *) Name
{
Return _ name;
}
-(Void) setname :( nsstring *) Name
{
_ Name = Name;
}
@ End
1 @ public (public) can be directly accessed anywhere on the premise of an object.
2 @ protected (protected) can only be accessed in the object methods of the current class and subclass
3 @ private (private) can only be accessed directly in the object method of the current class
4 @ package (Framework-level) the scope is between private and public. You can directly ask by variable name as long as you are in the same framework.
5 @ InterfaceBy default, the declared member variables are public, and the member variables declared in @ implatation are private.
OC variable scope