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
TJ von Stein
1,188 PointsI would like to hear someone explain void methods and return types if they have a chance. Thanks!
void methods, return types
1 Answer
Jacob Bergdahl
29,119 PointsIt's simple! The return type is the kind of variable that the method returns. A return type of void means that the method won't return anything at all.
private static void doSomething() {
// this method doesn't return anything, but it can still do useful things!
}
private static String getHello() {
// this method returns a String!
return "Hello!";
}
// Let's call the methods! Imagine that we are in a relevant place in the code.
// The first one doesn't return anything.
doSomething();
// But this method does! Store it in a variable.
String example = getHello();