자격증/OCJP_ExamB

QUESTION 53

IT grow. 2018. 7. 13. 21:18
반응형
QUESTION 53
Given:
04. import java.io.*;
05.
06. public class Talk {
07. public static void main(String[] args) {
08. Console c = new Console();
09. String pw;
10. System.out.print("password: ");
11. pw = c.readLine();
12. System.out.println("got " + pw);
13. }
14.}
If the user types the password aiko when prompted, what is the result?
A. password: got
B. password: got aiko
C. password: aiko got aiko
D. An exception is thrown at runtime.
E. Compilation fails due to an error on line 8.
Solution : E




plus imformation 


Main.java:8: Console() has private access in java.io.Console

        Console c = new Console();

                    ^ 

1 error 

 

Line 8 should be: Console c = System.console(); 


반응형