Sunday, 18 August 2013

Why Java System.in.read() can call which is not a static method

Why Java System.in.read() can call which is not a static method

In java, java.lang.System class, which has an in static variable.
Declared as: public static final InputStream in
Which means that in is an InputStream varibale.
However I see some example, using System.in.read() to read input.


How can it do that, the read() method in InputStream is not a static
method, how can it be directlly call it? As my understanding, only static
method can call directly by a Class without creating an instance.

read() declartion: public abstract int read() throws IOException

No comments:

Post a Comment