Given the code fragment:
What is the result?
Given the code fragment:
What is the result?
The code reads the password without echoing characters on the console. The System.console() returns a console object which is used to read the password without displaying it. Therefore, there will be no compilation error at either line n1 or line n2, and the IOException is not relevant in this context.
C. The code reads the password without echoing characters on the console. tested
C is correct
Answer C. Tested
Answer is : C
C tested, on windows 10 CMD.
C is the correct answer
With given options answer is C. Since input is read from user and it is not printed. Also System.console() might return null if console is not available and NPE might be thrown, but that option is not in answers.
C. The code reads the password without echoing characters on the console. tested
import java.io.Console; public class Main { public static void main (String[] args) { Console console = System.console(); char[] pass = console.readPassword("Enter password:"); // line n1 String password = new String(pass); // line n2 } } C:\cjava\809>javac Main.java C:\cjava\809>java Main Enter password: C:\cjava\809> Answer is C
Answer is : C
Answer is A. Exception in thread "main" java.lang.NullPointerException
This is a bug #122429 of eclipse
Answer is A.
Answer is D tested