InputStream是一个抽象类。那么我们怎样才能访问System.in.And而且int read()是InputStream类中的一个抽象方法。那么如果读取的话我们如何访问System.in.read()方法()是一种抽象方法。 像是System.in中的InputStream类的对象引用?
int a=System.in.read();
System.out.println((char)a);
InputStream是一个抽象类。那么我们怎样才能访问System.in.And而且int read()是InputStream类中的一个抽象方法。那么如果读取的话我们如何访问System.in.read()方法()是一种抽象方法。 像是System.in中的InputStream类的对象引用?
int a=System.in.read();
System.out.println((char)a);
被System.in中的InputStream类的对象引用?
是的!特此声明/记录在系统类:
/**
* The "standard" input stream. This stream is already
* open and ready to supply input data. Typically this stream
* corresponds to keyboard input or another input source specified by
* the host environment or user.
*/
public final static InputStream in = null;
但在运行时是一个BufferedInputStream
类的引用
我建议你阅读关于Java中抽象和继承方法的更多信息。
如果扩展抽象类,则必须实现其抽象方法。通过这种方式,您可以为它提供一个实现,可以由消费者调用。
System.in
是一个类的实例,它直接扩展了InputStream
而不是InputStream
。
也许看看[this](http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html)... – Lino
你应该检查System类中的initializeSystemClass()方法,它包含这些Streams如何初始化的细节。 – dvsakgec
我不认为这是一个坏问题。一个人不应该投票。 – Joshua