Java中System.out的类型是什么? [英] What is the type of System.out in Java?

查看:539
本文介绍了Java中System.out的类型是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆