Void in context


#1

In this exercise

https://www.codecademy.com/courses/learn-java/lessons/object-oriented-programming/exercises/using-methods-2?action=resume_content_item

it tries to explain what void means in a method and says it means in returns nothing, but in the exercise it uses to help explain it has lines like this

public void bark()
{
System.out.println(“Woof!”);
}

wouldn’t that be considered to return a string with woof? What about this am I not understanding, am I misinterpreting the meaning of returning a value? Thanks.


#2

Nothing is returned. The string is sent to the print buffer and then poof! It’s gone. A return would be tangible and still in play.


#3

Thanks! So a return would be if it was getting a value like an int to store in a variable or something? I think that is the part that I am getting confused by.


#4

Correct. It would different if we wrote,

    return "Woof!"

and,

String dogSpeak = bark();
System.out.println(dogSpeak);

#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.