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 trialDinu Comendant
6,049 PointsWhen do I need to use a parameter?
This question had to come quite sooner, but I thought that with more practice I'll eventually figure it out. Still, I'm looking at the codes in the videos and still don't understand when is actually necessary to use parameters. For me, it feels like a parameter would fit everywhere and vice-versa (wouldn't fit). What questions should I give myself in order to understand if a method requires parameters in it or not?
1 Answer
Ronald Williams
Java Web Development Techdegree Graduate 25,021 PointsHere is a question you can ask yourself: Does this method require outside variables / information? Here are two scenarios to help:
1). A method that when called plays your music:
// notice there is no parameter in this method
public void play() {
playingMusic = true;
}
2). A method that adds a song to your favorite playlist:
// notice this method takes a song i.e. the one you are adding to the playlist
public void addSong(Song song) {
favoritePlaylist.add(song);
}