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 trial

Java Java Data Structures - Retired Efficiency! Queueing

Hassaan Ahmad
Hassaan Ahmad
1,979 Points

Why is playNext() method made public when it could've been made private as other methods?

playNext() method is made public even when it is only being called from another public method of the same class. Isn't it better to make it private as it is not being accessed directly anywhere out of the KaraokeMachine class?

Good point, I also thought about this as we didnt use this method outside of the KaraokeMachine class. any one of u knows? Steven Parker Tonnie Fanadez Eric McKibbin

1 Answer

Steven Parker
Steven Parker
231,236 Points

Wow, old question. It may be that only the folks tagged will ever see the new comment. :wink:

But even if the current implementation only calls a method from inside the same class, one reason to make it public might be if it serves a function that might be of use to future code.

I suspect that's what the instructor had in mind when he said "Let's make it public, so anybody can call this one, if they wanted to."