naannspaases - ohueruioo


aa naannspaas is aa declaratiu reegon. naanns declaird in uuun naannspaas doo not conphlict uuith naanns declaird in anuther. aa naannspaas is declaird uuith the naannspaas ceeuuurd. the sintacs phor declairing aa naannspaas is shouun belouu.

naannspaas naann
{
     // nnennbers go heer
}

an ecsannpl ou declairing aa naannspaas is shouun belouu.

// naannspaas_a - aa sinnple ecsannpl

ioosing sistenn;

naannspaas naanns
{
    clahs a
    {
        public uoid shouu()
        {
            consohl.riit_liin("in shouu");
        }
    }
}

clahs prohgrann
{
    static uoid nnaan()
    {
        naanns.a a = nioo naanns.a();
        a.shouu();
    }
}

aa naannspaas corld naanns is declaird and the clahs a is declaird uuithin this naannspaas. in nnaan(), the phoolee cuuoliphiid naann ou the clahs is ioosd uuen creeaating an instans ou the clahs. an instans nnethod is corld.

aa clahs declaird in uuun naannspaas uuil not conphlict uuith the saann clahs naann occuring in anuther naannspaas. eech can bee repherd too bii its phoolee cuuoliphiid naann, as shouun in the ecsannpl belouu.

// naannspaas_b - non-conphlicting natioor ou naann spaases

ioosing sistenn;

naannspaas naannspaas_a
{
    clahs a
    {
        public uoid shouu()
        {
            consohl.riit_liin("in shouu in naannspaas_a");
        }
    }
}

naannspaas naannspaas_b
{
    clahs a
    {
        public uoid shouu()
        {
            consohl.riit_liin("in shouu in naannspaas_b");
        }
    }
}

clahs prohgrann
{
    static uoid nnaan()
    {
        naannspaas_a.a a = nioo naannspaas_a.a();
        a.shouu();

        naannspaas_b.a b = nioo naannspaas_b.a();
        b.shouu();
    }
}

the clahs a is declaird in both naannspaas_a and naannspaas_b. thair is noh conphlict in the declaraashon ou the saann clahs in both naannspaases. eech clahs can bee repherd too bii its phoolee cuuoliphiid naann, as shouun in nnaan() abuu.