java – System. What input class does in belong to and why?
code
import java.io.*; class ioTest1{ public static void main(String args[]){ System.out.println(system.in.getClass()); } }
Return system In belongs to bufferedinputstream class Why?
Because system will be system In is defined as InputStream, and I can see how the result is not impossible But why can't previous code return another class inherited from InputStream, such as datainputstream?
Solution
As explained in the comments, nothing can stop the system In from datainputstream, but since bufferedinputstream is an input stream without rhetoric, it contains buffered data (always a good idea)), giving the most general input possible
If the program is receiving pipeline binary data, or if the program receives text data from the user, the developer can wrap the buffer stream with, for example, datainputstream
system. In is a bufferedinputstream because it doesn't need anything else