The read()
method is declared abstract in InputStream
class. But we are able to read from keyboard using System.in.read()
.
My question is that 'in' is a reference of InputStream
class. So to use read()
method in has to refer to some subclass of InputStream
.
To what class does 'in
' refer to by default? Can we write a code to find answer to this question?
To answer your specific question: Yes, you can find out the class of System.in
by writing code.
This is the application you are looking for:
public class SystemDotInClassFinder {
public static void main(String[] args) {
System.out.println(System.in.getClass().getName());
}
}
Running this script produces:
java.io.BufferedInputStream