Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(java: methods): which of the following code snippers can be used for defining a

ID: 3623754 • Letter: #

Question

(java: methods): which of the following code snippers can be used for defining a method that does not return a value? The method should accept a string and then display the string followed by "And that's all folks!" on a sepparate line.
a.
public static String display_ message(String str)
{
System.out.println(str);
System.out.println("And that's all folks!");
}
b.
public static void display_message(String str)
{
System.out.println(str);
System.out.printn("And that's all folks!");
}

c.
public static void display_message(String str)
{
System.out.println(str);
System.out.println("And that's all folks!");
return str;

d.
public static void display_message()
{
system.out.println(str);
system.out.println("And that's all folks!");

Explanation / Answer

The answer is (b). (a) is eliminated because the method signature ("public static String display_ message(String str)") specifies String as a return value, but the question said we should not have any return value (it should be void instead of String) (d) is eliminated because it does not take an argument (so it won't know what string to display). This is indicated by the "()" after display_message. (c) is eliminated because it ends with "return str;" which means it has to return a value. In fact, none of the snippets would compile except (b).