Given the following methods: static String saySomething(String name) { return "Hi, " + name; } static String saySomething(String name, int count) { String greeting = ""; for(int i = 0; i < count; i++) { greeting += "Welcome, " + name + "\n"; } return greeting; }Which of the following would need to be called to result in the output:Hi, Sophiaa.)System.out.println(saySomething(1,"Sophia"));b.)System.out.println(saySomething("Sophia",1));c.)System.out.println(saySomething("Hi Sophia"));d.)System.out.println(saySomething("Sophia"));
Question
Given the following methods: static String saySomething(String name) { return "Hi, " + name; } static String saySomething(String name, int count) { String greeting = ""; for(int i = 0; i < count; i++) { greeting += "Welcome, " + name + "\n"; } return greeting; }Which of the following would need to be called to result in the output:Hi, Sophiaa.)System.out.println(saySomething(1,"Sophia"));b.)System.out.println(saySomething("Sophia",1));c.)System.out.println(saySomething("Hi Sophia"));d.)System.out.println(saySomething("Sophia"));
Solution
The correct answer is d.) System.out.println(saySomething("Sophia"));
This is because the method saySomething(String name) takes a single String parameter and returns a greeting that includes the name. The other options either use incorrect parameters or call the overloaded method saySomething(String name, int count) which returns a different greeting.
Similar Questions
Given the following method: static String saySomething(String name) { String output = ""; if (name.length() < 5) { output = name + ", your name is short."; } else { output = name + ", your name is long."; } return output; } What would the output be to the screen after following statement? System.out.println(saySomething("Randy"));Randy, your name is long.Randy, your name is short.RandysaySomething("Randy")
Given the following method, the output is expected to have Welcome, name repeated based on the count passed in by the user. What is the issue? static String saySomething(String name, int count) { String greeting = ""; for(int i = 0; i < count; i++) { greeting += "Welcome, " + name + "\n"; } return count; }a.)The return statement.b.)The concatenation.c.)The loop.d.)The parameters.
public class Code { public static void main(String[] args) { method(null); } public static void method(Object o) { System.out.println("Object method"); } public static void method(String s) { System.out.println("String method"); }}
public class Test { public void m1(String arg1) { arg1="Test"; } public static void main(String[] args) { Test test1= new Test(); String s= "Hello"; test1.m1(s); System.out.println(s); }}
Consider the following program.public class Main { public static void main(String args[]) { String[] names = new String[2]; names[0] = "Alice"; names[1] = "Bob"; names[2] = "Charlie"; System.out.println(names[2]); }}Which of the following is an output of the above program? a. Charlie b. Bob c. Alice d. Compilation Error
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.