0

Using Scanner class, input from keyboard is read. We pass System.in as an oject to Scanner class while constructing it. "in" is an object type of InputStream abstract class. In InputStream class "in" has been made as static as well as final and been initialized to null (as per the source code given for windows). Then it can not be changed anywhere else.

So basically what we pass to Scanner class is a reference to a null value. If this is the case, then how the input from keyboard is read correctly ?

Can you please help me.

user3103957
  • 636
  • 4
  • 16
  • Can you please help me with another question... – user3103957 Mar 03 '17 at 06:15
  • The variable "in" in System class is of type PrintStream class. The read() method in this class is responsible for reading basic unit. This has been defined as abstract method. This class has in fact has so many overloaded methods of the same; but they in turn call the abstract read() method. When we have the following code, can you please tell me in whihc class the read() method is defined ? String s = new Scanner(System.in).readLn(); Thanks!! – user3103957 Mar 03 '17 at 06:27
  • I am sorry.. I supposed to mention InputStream in the above comment. – user3103957 Mar 03 '17 at 06:36

0 Answers0