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是不是之类对象,我很迷惑,希望大家给小弟解疑释惑。

解决方案 »

  1.   

    System.out是PrintStream类型的
    PrintStream是OutputStream 的子类
    PrintStream具备向屏幕打印的功能
    out=System.out之后,out自然具备了向屏幕打印的功能
    看下jdk就明白了
      

  2.   

    看看api就知道了,System类有三个字段,static PrintStream err,static PrintStream  in,
    static PrintStream  out;  当out = System.out 后out自然就有了输出的功能。
      

  3.   

    楼上的二位高手当out = System.out 后out自然就有了输出的功能。
    我就这里 不明白 PrintStream是OutputStream 的子类     实例化对象之后不是向父类转型了吗??这时候父类是看不到子类对象里的  想屏幕打印的方法呀
      

  4.   

     java 默认引入java.lang.*;
    看源码
    /**
     * 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();
      

  5.   

    out=System.out,这里发生了向上转型,但对象实例还是PrintStream的对象实例,最终调用的还是PrintStream上的print方法。这是java里的运行时类型识别