Consider the following program and replace the statement #1 and #2 with appropriate declarations:
import java.io.Console; class Login {// www . j a va 2 s . c o m public static void main(String []args) { Console console = System.console(); if(console != null) { //#1 //#2 userName = console.readLine("Enter your username: "); password = console.readPassword("Enter password: "); System.out.println(userName + " ," + password); } } }
a) String userName = null;/*from w w w . ja v a 2 s .co m*/ char[] password = null; b) String userName = null; String password = null; c) char[] userName = null; String password = null; d) char[] userName = null; char[] password = null;
a)
The readLine()
method returns a String object while the readPassword()
method returns an array of char.