Domanda

If we treat tree as an object then what will be its leaf and branches?
Similarly, if we treat dog as an object then what will be its legs,mouth and eyes?

È stato utile?

Soluzione

A tree HAS a set of branches. Each branch HAS a set of leaves.

That is, (pseudocode)

class Tree {
    Branch[] branches;
}

class Branch {
    Leaf[] leaves;
}


class Leaf {

}

Similarly with the dog: a dog HAS a collection of eyes; it also has a collection of legs; and it has a mouth.

class Dog {
    Leg[] legs;
    Mouth mouth;
    Eye[] eyes;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top