Java中System.out的类型是什么? [英] What is the type of System.out in Java?
问题描述
我只是Java的新手.我想知道System.out.println()
的使用方式. Out是System
类内部的静态字段. out
的类型是PrintStream
.但是,当我看到PrintStream
类的构造函数时,它采用了OutputStream
类型的参数,据我所知,我们无法创建抽象类的对象.在这种情况下,我们必须将某些子类的对象传递给PrintStream
的构造函数.那是什么班? System.in
也是如此.它也是InputStream
的引用,但是由于InputStream
是抽象的,它指向的对象是什么类型?
I am just a newbie in Java. I was wondering the way System.out.println()
is used. Out is a static field inside System
class. The type of out
is PrintStream
. But when I saw the constructor of PrintStream
class, it takes a parameter of type OutputStream
and as far as I know we cannot create the object of an abstract class. In that case we must pass some subclass's object to the constructor of PrintStream
. What is that class? Same is the System.in
. It is also InputStream
's reference but what is the type of object it points to as the InputStream
is abstract?
推荐答案
PrintStream
包装BufferedOutputStream
,包装FileOutputStream
,后者写入控制台,该控制台具有自己的FileDescriptor
.
PrintStream
wraps BufferedOutputStream
, which wraps FileOutputStream
, which is writing into the console, which has its own FileDescriptor
.
这篇关于Java中System.out的类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!