What Is the Output of Console readLine and readPassword?
Short answer
A The console reads Duke and Java; String.valueOf(password) then prints the char[] password as Java in the final output line.
Question

Key Takeaways
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.
Common mistake: 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.
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
- https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/Console.html
- https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html
These links open the official vendor documentation in a new tab.
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?
What if the code printed the password char[] without String.valueOf?
Community Votes
100% of anonymous learners picked answer A. Votes are pick records left by other test-takers — they are not the verified answer.
Discussion 5 contributions
Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.
From public community threads 5
-
Omnisumem 👍 1 Answered Ato 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)); }}
-
ASPushkin 👍 1 Answered AString public static String valueOf(char[] data)) java.io.Console public char[] readPassword() Returns: A character array containing the password
-
d7bb0b2 👍 1that is correct because, readpassword retrive a char[], but in print method uses to string for this pass is visible
-
d7bb0b2 👍 1 Answered AA is correct eadpassword retrive a char[], but in print method uses toString method for this pass visible
-
Felipe47 👍 2A. Tested.
Reader comments & corrections
No reader corrections yet — spotted an error or have a note? Share it below.