Setting attributes in one class, that reference another class

In the following exercise:, I am intrigued about the class attributes of, because they seem to reference another class and then the constructor (?) assigns these attributes to values defined in So is there a set of rules for doing this? E.g. if you want to assign attributes (e.g. accountOne) values from another class (e.g. inputBalance), you have to reference that class when creating attributes (e.g. private CheckingAccount accountOne;) ? and then call a new instance of this constructor to assign accountOne values e.g. new CheckingAccount(“Zeus”, 100, “1”) ? Is there a name for this process ?

A few things are happening here. The CheckingAccount class is automatically imported into (because they are in the same folder). This is why you can create a new CheckingAccount object and assign it as an instance variable of the Bank class.

For naming this process, you are really just creating an object. Or perhaps “instantiating a CheckingAccount object”.
When an object has another object as one of its instance variables, that is called Object Composition.

1 Like