1Z0-819 · Question #63
public class Main { public static void main(String[] args) { try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { String input = br.readLine(); System.out.print("Input…
The correct answer is D. System.in is the standard input stream. The stream is already open. System.in is a static field of the java.lang.System class representing the standard input stream - it is always open from JVM startup, which is why wrapping it in a BufferedReader works immediately without any explicit open call, as the code demonstrates. Why the distractors…
Question
Options
- ASystem.out is the standard output stream. The stream is open only when System.out is called
- BSystem.in cannot reassign the other stream.
- CSystem.err is printstream and java.OutputStream by default.
- DSystem.in is the standard input stream. The stream is already open.
How the community answered
(36 responses)- A8% (3)
- B14% (5)
- C6% (2)
- D72% (26)
Explanation
System.in is a static field of the java.lang.System class representing the standard input stream - it is always open from JVM startup, which is why wrapping it in a BufferedReader works immediately without any explicit open call, as the code demonstrates.
Why the distractors are wrong:
- A is false because
System.outis always open too - it's not opened on-demand when called; it's a pre-openedPrintStreamavailable from JVM startup. - B is false because
System.incan be reassigned usingSystem.setIn(InputStream), which replaces the standard input with another stream. - C is partially misleading -
System.erris indeed aPrintStream, butPrintStreamextendsFilterOutputStreamwhich extendsOutputStream, notjava.io.OutputStreamdirectly as a separate interface; more importantly, the phrasing "by default" is vague and the statement conflates inheritance with instantiation in a way that makes it incorrect as written.
Memory tip: Think of the three standard streams (System.in, System.out, System.err) as always-on pipes - they're wired up before your main method runs and stay open for the JVM's lifetime, just like stdin/stdout/stderr in any Unix process.
Topics
Community Discussion
No community discussion yet for this question.