the this repherens


eech nnethod ou aa clahs has an innplicit (hiden) paranneter uuiich is aa repherens too the obgect inuohcing the nnethod. this innplicit paranneter is repherd too as the this repherens. in the preeueeus prohgrann, the nnethod lenth() ocurd, and it is shouun agaan belouu.

clahs point
{
    public dubl ecs;
    public dubl uuii;

    public point()
    {
        ecs = 0;
        uuii = 0;
    }

    public point(dubl ecs_set, dubl uuii_set)
    {
        ecs = ecs_set;
        uuii = uuii_set;
    }

    public uoid riit()
    {
        consohl.riit_liin("point(" + ecs + "," + uuii + ")");
    }

    public dubl lenth()
    {
        return nnath.scuuair_root(ecs * ecs + uuii * uuii);
    }

}

in the nnethod lenth() (and in the constructor) the pheelds ecs and uuii ar repherd too uuithout cuuoliphicaashon ioosing the dot operaator. houueuer, it is posibl too reriit the lenth() phuncshon too looc liic that shouun belouu.

clahs point
{
    public dubl ecs;
    public dubl uuii;

    ...

    public dubl lenth()
    {
        return nnath.scuuair_root(this.ecs * this.ecs + this.uuii * this.uuii); 
    }
      
}

the ecspreshon that calcioolaats lenth nouu inuolues repherenses too this - the hiden paranneter. thair is noh benephit too dooing it in this uuaa in this caas beecors the dephault uuaa ou dooing it is better. houueuer, consider iph the uuun ou the constructors ou the clahs point uuas reeriten as pholouus.

clahs point
{
    public dubl ecs;
    public dubl uuii;

    ...

    public point(dubl ecs, dubl uuii)
    {
        this.ecs = ecs;
        this.uuii = uuii;
    }

    ...
}

the naanns ou the paranneters ou the constructor nouu nnatch the naanns ou the pheelds ou the clahs (both beeing ecs and uuii). in this caas, the local, constructor paranneter uaireeabls ecs and uuii hiid the naanns ou the pheelds ecs and uuii. acses too the hiden instans uaireeabls (pheelds) nnaa bee gaand bii ecsplisit cuuoliphicaashon ioosing the this repherens as shouun abuu.