Java Java Data Structures Efficiency! Design the UI

Prasoon Shukla
Prasoon Shukla
3,426 Points

Parameters in a constructoer

While creating KaraokeMachine constructor, why do we only pass songBook as a parameter and not others like may be reader and menu?

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 55,555 Points

In the constructor, only parameters needed to initialize the class are passed. Since the local variables mReader and mMenu are defined within the constructor they don't need to be passed any arguments for initialization. Because the constructor doesn't define a local value for mSongBook, the constructor needs to be passed an argument for the parameter songBook so that the constructor can simply assign songBook to mSongBook

Prasoon Shukla
Prasoon Shukla
3,426 Points

Thanks Chris. I get it now. Any thing constant can be defined within constructor and hence it would not need an external parameter to make the object work.