• Post Reply Bookmark Topic Watch Topic
  • New Topic

How System.in of type InputStream is initialized?  RSS feed

 
Quazi Irfan
Ranch Hand
Posts: 104
1
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that abstract class can only be referenced but not initialized. InputStream is an abstract class. But in the System class I see the following declaration,



So to use something like System.in.read(), variable in needs to be initialized.

But how java initialize a reference to an abstract class. Or do System.in is initialized as 'console input stream' somewhere that extends InputStream.
 
Quazi Irfan
Ranch Hand
Posts: 104
1
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quazi Irfan wrote:
But how java initialize a reference to an abstract class. Or do System.in is initialized as 'console input stream' somewhere that extends InputStream.


To answer my own question, I've found



So is JVM doing the initialization of in variable?
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's correct. Since System.in and System.out are supplied automatically to all application code, it must be the case that they are assigned values by code which is (most likely) in the System class.
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is one of those things you do not need to know. There is probably some native method which links to the console. Then it creates an instance of a concrete subclass of InputStream.
System.out.println(System.in.getClass().getName());
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!