66.2k views
3 votes
When an object of one class is a data field within another class, they are related by ____.

a.
composition

b.
extension

c.
is-a

d.
scope

1 Answer

4 votes

Answer:

a. composition

Step-by-step explanation:

When an object of one class is a data field in another class, the two classes are related by composition. In particular the containing class is composed using the contained class. For example:

class container {

contained c;

int a;

}

class contained {

int b;

}

Here the container class is containing an instance of contained class creating a composition relation.

User Ali Turki
by
7.6k points