Search code examples
javaprintstream

where is out object created?


There is a static PrintStream reference variable in System class,which calls the print and println methods,but my question is that where does this reference variable is pointing to ? where we have in actual created the object so we are able to call the methods of Prinstream class,as we need an object to class the instance methods of the class,not the reference variable of the class

now my question is how is out able to call the println method,though its not an object,but only a reference variable?


Solution

  • In the method initializeSystemClass in class java.lang.System you can find things like:

    FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
          //...
    setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true));