Ask Question

The overloaded printString method is defined as follows: public static void printString (String s) { System. out. println (s); } public static void printString (String s, int n) { if (s. length () > n) printString (s. substring (0, n)); else printString (s); } Exactly one of these statements is such that, when executed, it causes the String "Scrum" to be printed to the output window. Which one?

+2
Answers (1)
  1. 30 March, 08:34
    0
    Complete Question:

    The overloaded printString method is defined as follows: public static void printString (String s) { System. out. println (s); } public static void printString (String s, int n) { if (s. length () > n) printString (s. substring (0, n)); else printString (s); } Exactly one of these statements is such that, when executed, it causes the String "Scrum" to be printed to the output window. Which one?

    A. printString ("Scrump");

    B. printString ("Scrumptious");

    C. printString ("Scrumptious", 4);

    D. printString ("Scrumptious", 5);

    E. printString ("Scrumptious", 6);

    Answer:

    Option D: printString ("Scrumptious", 5);

    Explanation:

    The method call printString ("Scrumptious", 5); is to the second overloaded method since it is the one that accepts two parameters.

    This method prints the substring from 0 to n, in this call, n = 5 (i. e the indexes 0,1,2,3,4) and these are the letters Scrum that is outputed to the console
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “The overloaded printString method is defined as follows: public static void printString (String s) { System. out. println (s); } public ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers