Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat does void do in java?
    primarykey
    data
    text
    <blockquote> <p>The return type—the data type of the value returned by the method, or void if the method does not return a value.</p> </blockquote> <p><a href="http://download.oracle.com/javase/tutorial/java/javaOO/methods.html" rel="noreferrer">http://download.oracle.com/javase/tutorial/java/javaOO/methods.html</a></p> <p>Okay, then.. Here is my question:</p> <pre><code>public class EnumTest { Day day; public EnumTest(Day day) { this.day = day; } public void tellItLikeItIs() { switch (day) { case MONDAY: System.out.println("Mondays are bad."); break; case FRIDAY: System.out.println("Fridays are better."); break; case SATURDAY: case SUNDAY: System.out.println("Weekends are best."); break; default: System.out.println("Midweek days are so-so."); break; } } public static void main(String[] args) { EnumTest firstDay = new EnumTest(Day.MONDAY); firstDay.tellItLikeItIs(); EnumTest thirdDay = new EnumTest(Day.WEDNESDAY); thirdDay.tellItLikeItIs(); EnumTest fifthDay = new EnumTest(Day.FRIDAY); fifthDay.tellItLikeItIs(); EnumTest sixthDay = new EnumTest(Day.SATURDAY); sixthDay.tellItLikeItIs(); EnumTest seventhDay = new EnumTest(Day.SUNDAY); seventhDay.tellItLikeItIs(); } } </code></pre> <p><a href="http://download.oracle.com/javase/tutorial/java/javaOO/enum.html" rel="noreferrer">http://download.oracle.com/javase/tutorial/java/javaOO/enum.html</a></p> <p>The above code does not work without void.</p> <pre><code>Exception in thread "main" java.lang.Error: Unresolved compilation problems: The method tellItLikeItIs() is undefined for the type EnumTest </code></pre> <p>What did I miss out? Why is there a void in there? And it does return a string?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload