大家都知道,java.lang包是在JVM运行时自动导入的,所以我们在写代码时不需要写上:
import java.lang.*;但是:
System.out对象是OutputStream类的,而这个类却是在java.io包中定义的,但java.io包不是被自动导入的。这究竟是个怎么回事呢?

解决方案 »

  1.   

    java.io.OutputStrean import 了 java.lang.Object
      

  2.   

    晕倒,System是lang底下的就OK啦,后边由System调用的方法引用的包不用管
      

  3.   

    自己查一下JDK API 就好了
      

  4.   

    朋友,你的理解上有点问题,可以看见文档,System.out并非是outputStream的对象,out是java.lang.System中的一个静态字段,可以使用类名直接调用。
      

  5.   


    你说的没错,out是System的一个静态成员,但是,这个成员的类型是OutputStream啊!或者,换种说法,如果我写代码时不写import java.io.*; 直接用OutputStream ops; 编译都不会通过的,这是为什么呢?
      

  6.   


    我想你的意思也许是在java.lang包中导入了java.io包,但为什么我们在写代码时不能直接用io包中的类呢?
      

  7.   

    给你看源码吧,再怎么说也是浮云
    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 java.nio.channels.Channel;
    import java.nio.channels.spi.SelectorProvider;
    import sun.nio.ch.Interruptible;
    import sun.reflect.Reflection;
    import sun.security.util.SecurityConstants;
    import sun.reflect.annotation.AnnotationType;/**
     * 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.162, 04/01/09
     * @since   JDK1.0
     */
    public final class System {
        private static native void registerNatives();
        static {
            registerNatives();
        }    ......
        public final static PrintStream out = nullPrintStream();
    System是lang包下的,System.out是PrintStream打印流类型顶部不是有导入import java.io.*  吗?