1. import java.io.* ;
2. public class IODemo14
3. {
4. public static void main(String args[]) throws Exception
5. {
6. // 通过子类完成不同的功能
7. OutputStream out = null ;
8. // System.out是PrintStream,是OutputStream子类
9. out = System.out ;
10. // 现在的out对象具备了向屏幕上打印内容的能力
11. String str = "HELLO MLDN --> LXH" ;
12. out.write(str.getBytes()) ;
13. out.close() ;
14. }
15. };我不明白的是 为啥 out = System.out ; 之后 out对象就具备向屏幕打印内容的功能了呢??还有 就是 这里的 out是不是父类对象而 System.out是不是之类对象,我很迷惑,希望大家给小弟解疑释惑。
2. public class IODemo14
3. {
4. public static void main(String args[]) throws Exception
5. {
6. // 通过子类完成不同的功能
7. OutputStream out = null ;
8. // System.out是PrintStream,是OutputStream子类
9. out = System.out ;
10. // 现在的out对象具备了向屏幕上打印内容的能力
11. String str = "HELLO MLDN --> LXH" ;
12. out.write(str.getBytes()) ;
13. out.close() ;
14. }
15. };我不明白的是 为啥 out = System.out ; 之后 out对象就具备向屏幕打印内容的功能了呢??还有 就是 这里的 out是不是父类对象而 System.out是不是之类对象,我很迷惑,希望大家给小弟解疑释惑。
解决方案 »
- 关于多线程的一个问题
- 统计1-100之间质数的个数
- ResultSet 是一次返回所有,还是通过next一次次去连接db取? 急
- 如何编写代码实现从access数据库中将几个表的数据导入到sql serve\Oracle中去?
- 请教一个算法问题
- 这句话到底什么意思。它有什么功能;体现类体的什么特性?
- 在JFileChooser里双击.lnk文件无法转移到目标文件夹!
- 关于键盘事件的小问题?
- 在Java中如何才能像vb中的treeView那样从数据库中生成树?
- CSDN的高手都到哪去了?!!! 再不解决,小弟要跳楼了。。。。在线等待
- 向数据库插入字符数据时,出现空格,造成无法查询
- 关于数据库连接的问题
PrintStream是OutputStream 的子类
PrintStream具备向屏幕打印的功能
out=System.out之后,out自然具备了向屏幕打印的功能
看下jdk就明白了
static PrintStream out; 当out = System.out 后out自然就有了输出的功能。
我就这里 不明白 PrintStream是OutputStream 的子类 实例化对象之后不是向父类转型了吗??这时候父类是看不到子类对象里的 想屏幕打印的方法呀
看源码
/**
* The <code>System</code> class contains several useful class fields
* and methods. It cannot be instantiated.
*
* <p>Among the facilities provided by the <code>System</code> class
* are standard input, standard output, and error output streams;
* access to externally defined properties and environment
* variables; a means of loading files and libraries; and a utility
* method for quickly copying a portion of an array.
*
* @author unascribed
* @version 1.150, 03/22/06
* @since JDK1.0
*/
public final class System { /**
* The "standard" output stream. This stream is already
* open and ready to accept output data. Typically this stream
* corresponds to display output or another output destination
* specified by the host environment or user.
* <p>
* For simple stand-alone Java applications, a typical way to write
* a line of output data is:
* <blockquote><pre>
* System.out.println(data)
* </pre></blockquote>
* <p>
* See the <code>println</code> methods in class <code>PrintStream</code>.
*
* @see java.io.PrintStream#println()
* @see java.io.PrintStream#println(boolean)
* @see java.io.PrintStream#println(char)
* @see java.io.PrintStream#println(char[])
* @see java.io.PrintStream#println(double)
* @see java.io.PrintStream#println(float)
* @see java.io.PrintStream#println(int)
* @see java.io.PrintStream#println(long)
* @see java.io.PrintStream#println(java.lang.Object)
* @see java.io.PrintStream#println(java.lang.String)
*/
public final static PrintStream out = nullPrintStream();