is System.in an object reference of InputStream class?

后端 未结 3 953
不知归路
不知归路 2021-01-16 16:38

InputStream is an Abstract class.Then how are we able to access System.in.And moreover int read() is an abstract method in InputStream class.Then how are we able to access S

3条回答
  •  一生所求
    2021-01-16 17:06

    is System.in an object reference of InputStream class?

    yes!, it is declared/documented in the System class:

    /**
     * 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;
    

    but at runtime is a reference to a BufferedInputStream class

    so ou are not instantiating an abstract class

提交回复
热议问题