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

coder5837
1,535 Pointswhat exactly is a public void
very simple terms please
3 Answers

Craig Dennis
Treehouse TeacherYep! Doesn't necessarily have to do display, it might change the internal state of object, but just not return anything back to the caller.

Craig Dennis
Treehouse TeacherThis sounds like you are talking about a method declaration. Meaning you are explaining what your object can do.
In this case, void is used to state that nothing is returned from the method. Some methods return a value, but this will not.
Like this
public void say sayHello() {
System.out.println("hello");
}
Versus one that returns an int.
public int addNumbers(int first, int second) {
return first + second;
}
That clear things up?

coder5837
1,535 Pointsum could you clear up what it means to return an int? and also what it means to return anything?

Craig Dennis
Treehouse TeacherSo if those methods were called it would be like this:
// Add *returns* 5
int answer = obj.addNumbers(2, 3);
// Say hello does not return anything, it just runs
obj.sayHello();
Make sense? Sometimes you want a method to provide, or return, an answer, and sometimes you don't need it to. Because Java is strongly typed, you must define what you are expecting the method to do.
That help clear things up?

coder5837
1,535 Pointsohhh so basically if it returns something it's like interactive with the program but if it doesn't then it's just for display?
coder5837
1,535 Pointscoder5837
1,535 Pointsokay thank you so much!