|
SCJP : java.io.Console Mock Exam Practice Questions
Questions no -1
What is the output for the below code ?
import java.io.Console;
public class Test {
public static void main(String... args) {
Console con = System.console();
boolean auth = false;
if (con != null)
{
int count = 0;
do
{
String uname = con.readLine(null);
char[] pwd = con.readPassword("Enter %s's password: ", uname);
con.writer().write("\n\n");
} while (!auth && ++count < 3);
}
}
}
options
A)NullPointerException
B)It works properly
C)Compile Error : No readPassword() method in Console class.
D)null
Correct answer is : A
Explanations : passing a null argument to any method in Console class will cause a NullPointerException to be thrown.
| |