Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialPrasoon Shukla
3,426 PointsParameters 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
Treehouse Moderator 68,441 PointsIn 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
3,426 PointsThanks 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.