Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 189

Given:

and the command:

java ConsoleTest

The user will input Duke and Java when the input is prompted.

What is the output?

    Correct Answer: D

    The Console.readPassword() method returns a char array rather than a String. When the char array is printed using String.valueOf(password), it invokes the default toString() implementation of the array, which results in a string representation of the array's hashcode (e.g., [C@4f6ee6e4), rather than the actual characters. Therefore, the correct output will include the memory address of the char array, not the actual password input, making option D the correct choice.

Discussion
Felipe47Option: A

A. Tested.

OmnisumemOption: A

to check for yourself: import java.util.*; import java.lang.Object.*; import java.io.Console; public class q189{ public static void main (String args[]){ Console console = System.console(); var name = console.readLine("Input Name: "); var password = console.readPassword("Input Password: "); System.out.println ("Name is: " + name + ", Password is: " + String.valueOf(password)); }}

ASPushkinOption: A

String public static String valueOf(char[] data)) java.io.Console public char[] readPassword() Returns: A character array containing the password

d7bb0b2Option: A

A is correct eadpassword retrive a char[], but in print method uses toString method for this pass visible

d7bb0b2Option: D

that is correct because, readpassword retrive a char[], but in print method uses to string for this pass is visible