This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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...
 
wood burning stoves
 
subject: System.in.read() - Abstract method?