System是JAVA LANG 包里的一个类 System.out代表System的一个对象吗?println是out的一个方法?搞不明白这里的关系

解决方案 »

  1.   

    这里是System类里面的out对象的定义:
    public static final PrintStream out也就是说out是System里面的一个PrintStream类型的对象
      

  2.   

    我给你贴一个源码,你就清楚了,兄弟,给分哦,呵呵。package java.lang;import java.io.*;
    import java.util.Properties;
    import java.util.PropertyPermission;
    import java.util.StringTokenizer;
    import java.security.AccessController;
    import java.security.PrivilegedAction;
    import java.security.AllPermission;
    import sun.net.InetAddressCachePolicy;
    import sun.reflect.Reflection;
    import sun.security.util.SecurityConstants;/**
     * 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"; a means of
     * loading files and libraries; and a utility method for quickly
     * copying a portion of an array.
     *
     * @author  Arthur van Hoff
     * @version 1.131, 01/29/03
     * @since   JDK1.0
     */
    public final class System {    /* First thing---register the natives */
        private static native void registerNatives();
        static {
            registerNatives();
        }    /** Don't let anyone instantiate this class */
        private System() {
        }    /**
         * The "standard" input stream. This stream is already
         * open and ready to supply input data. Typically this stream
         * corresponds to keyboard input or another input source specified by
         * the host environment or user.
         */
        public final static InputStream in = nullInputStream();    /**
         * 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();    /**
         * The "standard" error output stream. This stream is already
         * open and ready to accept output data.
         * <p>
         * Typically this stream corresponds to display output or another
         * output destination specified by the host environment or user. By
         * convention, this output stream is used to display error messages
         * or other information that should come to the immediate attention
         * of a user even if the principal output stream, the value of the
         * variable <code>out</code>, has been redirected to a file or other
         * destination that is typically not continuously monitored.
         */
        public final static PrintStream err = nullPrintStream();    /* The security manager for the system.
         */
        private static SecurityManager security = null;    /**
         * Reassigns the "standard" input stream.
         *
         * <p>First, if there is a security manager, its <code>checkPermission</code>
         * method is called with a <code>RuntimePermission("setIO")</code> permission
         *  to see if it's ok to reassign the "standard" input stream.
         * <p>
         *
         * @param in the new standard input stream.
         *
         * @throws SecurityException
         *        if a security manager exists and its
         *        <code>checkPermission</code> method doesn't allow
         *        reassigning of the standard input stream.
         *
         * @see SecurityManager#checkPermission
         * @see java.lang.RuntimePermission
         *
         * @since   JDK1.1
         */
        public static void setIn(InputStream in) {
    checkIO();
    setIn0(in);
        }    /**
         * Reassigns the "standard" output stream.
         *
         * <p>First, if there is a security manager, its <code>checkPermission</code>
         * method is called with a <code>RuntimePermission("setIO")</code> permission
         *  to see if it's ok to reassign the "standard" output stream.
         *
         * @param out the new standard output stream
         *
         * @throws SecurityException
         *        if a security manager exists and its
         *        <code>checkPermission</code> method doesn't allow
         *        reassigning of the standard output stream.
         *
         * @see SecurityManager#checkPermission
         * @see java.lang.RuntimePermission
         *
         * @since   JDK1.1
         */
        public static void setOut(PrintStream out) {
    checkIO();
    setOut0(out);
        }    /**
         * Reassigns the "standard" error output stream.
         *
         * <p>First, if there is a security manager, its <code>checkPermission</code>
         * method is called with a <code>RuntimePermission("setIO")</code> permission
         *  to see if it's ok to reassign the "standard" error output stream.
         *
         * @param err the new standard error output stream.
         *
         * @throws SecurityException
         *        if a security manager exists and its
         *        <code>checkPermission</code> method doesn't allow
         *        reassigning of the standard error output stream.
         *
         * @see SecurityManager#checkPermission
         * @see java.lang.RuntimePermission
         *
         * @since   JDK1.1
         */
        public static void setErr(PrintStream err) {
    checkIO();
    setErr0(err);
        }    private static void checkIO() {
            if (security != null)
        security.checkPermission(new RuntimePermission("setIO"));
        }
      

  3.   

    代码好长 你的意思是在System类中定义了一个PrintStream类的对象?Java中可以这样定义!刚学不是很懂,以后要多看看才能理解
      

  4.   

    LZ自己正解了,是System的一个对象,那个方法也是out这个对象的方法
      

  5.   

    哦,我明白了,JAVA里在PrintStream中已经定义了println函数,System就有了Println这个方法?JAVA中可以在自己的类中定义一个别的类的对象,然后通过这个类来调用别的类的方法吗?