Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes System.in.read() - Abstract method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "System.in.read() - Abstract method?" Watch "System.in.read() - Abstract method?" New topic
Author

System.in.read() - Abstract method?

Thomas Markl
Ranch Hand

Joined: Mar 08, 2001
Posts: 192
Why are these programs the same?
Why is it possible to say InputStream in = System.in. Is System.in an object which can be referenced?

P.S: I found a good posting on read() called "Abstract method read()" but I don't understand it. So i post this question.
Thanks.
Thomas
[ Edited to preserve formatting using the [code] and [/code] UBB tags. It'd be nice if Thomas would start doing this all by himself -ds ]
[ July 30, 2002: Message edited by: Dirk Schreckmann ]
Neil Laurance
Ranch Hand

Joined: Jul 18, 2002
Posts: 183
The class java.lang.System class contains the following 3 public constants:
public static final java.io.PrintStream err;
public static final java.io.InputStream in;
public static final java.io.PrintStream out;
What this means is that System.in is a type of InputStream. In fact, it will be a concrete subclass of this abstract class. However, you can just use the methods of InputStream, and the underlying methods will be called due to polymorphism. Similarly, you can create an alias to the System.in InputStream handle with the code:
InputStream in = System.in;
What this means is that in and System.in are both handles to the same underlying object.
Hope this hasn't confused you more...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: System.in.read() - Abstract method?
 
Similar Threads
int and char
read data from keyboard
File Letter Counter help
why wont this run
unicode value for char