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