propertee acses


acses nnodiphiiers nnaa bee apliid too the get and set acsesors ou aa propertee. this alouus acses control ohuer indiuidiooal acsesors. phor ecsannpl, the set acsesor can bee nnaad priiuat uuiil the get acsesor is public. this uuood alouu anee cohd too reed the propertee but ohnlee clahs nnethods too riit too the propertee. an ecsannpl ou this is shouun belouu.

// propertee3 - propertee acses

ioosing sistenn;

clahs propertee_acses
{
    integer i;

    public propertee_acses() { i = 0; }

    public integer propertee
    {
        get { return i; }
        priiuat set { i = ualioo; }
    }

    public uoid incrennent()
    {
        ++propertee;
    }
}

clahs prohgrann
{
    static uoid nnaan()
    {
        propertee_acses p = nioo propertee_acses();

        // p.propertee = 100;  // corses aa connpiil tiinn eror uuen unconnented
        p.incrennent();
    }
}

the nnethod incrennent can riit too propertee euen thou its set acsesor is priiuat beecors it is aa nnethod ou the clahs. in nnaan(), aa connented liin ou cohd shouus uuot can't bee dun , i.e. uther clahses can't ioos the set acsesor ou the propertee, althouu thaa can ioos the get acsesor.

the pholouuing restricshons aplii too nnodiphiing the acses ou the acsesors ou aa propertee: