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 trialRandy Cole
Courses Plus Student 2,494 PointsDoes the methods load(MAX_PEZ) and load(int pezAmount) have the same signatures?
I understand that MAX_PEZ is a constant member variable that is set to an integer (which is 12)... so does that make it equivalent to the (int pezAmount) parameter and thus sort of substituting pezAmount with MAX_PEZ? I feel like he explained this in the video but I just need clarification to be sure that's what's happening.
1 Answer
Jeremiah Montano
7,221 PointsThe method signature is the Method and the parameter it takes in, such as load(int pezAmount). This tells the program how many pez to put into the dispenser. If you use load(MAX_PEZ), this would constitute a call and not a method declaration and it would tell the program to call the load method and use the variable inside MAX_PEZ to load the dispenser, which would be 12. If you used load() in your main program, it would call the method load() which would tell the computer to default to MAX_PEZ, as listed below.
public class GoKart{
public static final int MAX_PEZ = 12;
private int mPezAmount
public void load(int pezAmount) {
//this method would be called if you used GoKart.load(4); or any other integer.
mPezAmount = MAX_PEZ;
}
public void load() {
//this method would be used if you called GoKart.load(); and would default the load to MAX_PEZ.
load(MAX_PEZ);
}
}
I hope this answer finds you well and is helpful. Happy coding!
Randy Cole
Courses Plus Student 2,494 PointsRandy Cole
Courses Plus Student 2,494 PointsThat pretty much clears it up man thanks!