What Is the Output of Console readLine and readPassword?
Given: and the command: java ConsoleTest The user will input Duke and Java when the input is prompted. What is the output? - 
Community Votes
100% of anonymous learners picked answer A. Votes are pick records left by other test-takers — they are not the verified answer.
Community Insight
It tests Console prompt and echo behavior plus the char[] conversion trap: String.valueOf(password) prints the typed password as Java, whereas direct char[] concatenation would produce a hash code.
This 1Z0-819 question tests Console.readLine and Console.readPassword plus how String.valueOf(char[]) renders the password. It establishes that the correct output is Duke for the name and Java for the password, not a char[] hash code.
A common wrong choice assumes readPassword returns a String or that printing its char[] always shows [C@..., but here String.valueOf(password) converts the returned char[] into readable text.
Community Discussion (5 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
Expert Analysis
Why the Answer Is Correct
The program calls console.readLine("Input Name: ") to echo and read Duke, then console.readPassword("Input Password: ") to read Java without echoing it. The final println combines name with String.valueOf(password); String.valueOf(char[]) returns a new String containing the password characters. Therefore the visible final line is "Name is: Duke, Password is: Java", so option A is correct. The prompt text and the silent password entry explain why only the prompts and final result appear, not "Input Password: Java".Why the Other Options Are Wrong
Options that show [C@... for the password would be right only if the code concatenated the char[] directly or called toString on it. Options that show the password echoed at the readPassword prompt are wrong because readPassword disables echo. Options that omit the final println or show null ignore that readPassword returns a populated char[] from the Java input. Thus none of those match the String.valueOf(char[]) conversion in the given code.Community Comment Notes
Omnisumem's test harness confirms the same flow by using String.valueOf(password) and printing the name and password after the two Console calls. ASPushkin points out that readPassword returns a char[] containing the password, which is exactly what String.valueOf(char[]) converts. d7bb0b2 notes that the char[] alone would not display the password the same way, and Felipe47 simply records "A. Tested." These comments align with the output that shows Java on the final line.Official Reference
Exam Strategy
Trace the Console calls in order and separate prompt text from echoed input: readLine echoes Duke, readPassword suppresses echo for Java. Then identify the exact conversion used in println; String.valueOf(char[]) prints the password characters, while direct char[] concatenation would print a hash code.
Frequently Asked Questions
Why is Java not shown after the Input Password prompt?
Console.readPassword suppresses echo while Java is typed, so the password appears only later when String.valueOf(password) is printed.
What if the code printed the password char[] without String.valueOf?
Direct concatenation or println's Object handling would produce a hash code like [C@... instead of Java; String.valueOf(char[]) prevents that.