请教个有个System.out的问题

leetow2006 2018-10-25 10:23:40
我们一般输出是System.out.println(),这里System是类名,out是类System中的静态的类成员,它是这样定义的:
public final static PrintStream out = null;但是这里的out没有实例化,而类PrintStream中的println是一个
普通的成员函数(不是静态的),非静态方法必须用对象.方法(参数)的形式来调用,这里println就是非静态方法,
而这里是out没有实例化,应该不是对象,那为什么我们可以System.out.println()使用呢?
...全文
352 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
uuxin. 2018-11-21
  • 打赏
  • 举报
回复
底层帮你把in赋值了,不是你看到的null
追鑫少年 2018-10-31
  • 打赏
  • 举报
回复
System.out是PrintStream的对象,在PrintStream中定义了一系列的print()和println()方法,所有“System.out.println”语句调用的实际上就是PrintStream类的方法。
an煮鸡蛋 2018-10-30
  • 打赏
  • 举报
回复
5楼正解,System类加载器加载static静态块后,就可以类名.静态方法使用了奥
北漂的菜小白 2018-10-30
  • 打赏
  • 举报
回复
System类是静态的,在类加载器加载以后,就在内存中有这个对象了,静态的对象是可以用类名.对象名来使用的
隐语者 2018-10-30
  • 打赏
  • 举报
回复
java.lang 包下面的所有类,Java会自动帮你引用,不需要你手动引包,另外这静态方法不用实例化。System类的所有方法都是静态方法!
kingmax54212008 2018-10-29
  • 打赏
  • 举报
回复
不需要实例化
qq_39936465 2018-10-29
  • 打赏
  • 举报
回复
可能我说的也不够正确,请参考下面的文章。 https://blog.csdn.net/quinnnorris/article/details/71077893?utm_source=gold_browser_extension
qq_39936465 2018-10-29
  • 打赏
  • 举报
回复
system 类为final类 是不能实例化的,system类里都是系统设定值不能改动,你可以看作常数。常数可以直接用,不用实例化。
stacksoverflow 2018-10-26
  • 打赏
  • 举报
回复
5楼正解
nayi_224 2018-10-26
  • 打赏
  • 举报
回复
引用 4 楼 leetow2006 的回复:
[quote=引用 2 楼 nayi_224 的回复:] registerNatives() --> initializeSystemClass() --> setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true)); --> private static native void setOut0(PrintStream out); 应该是这个了
这个过程在哪个函数或文件里能看到?[/quote] 就是System类的第一个方法
 * method for quickly copying a portion of an array.
 *
 * @author  unascribed
 * @since   JDK1.0
 */
public final class System {

    /* register the natives via the static initializer.
     *
     * VM will invoke the initializeSystemClass method to complete
     * the initialization for this class separated from clinit.
     * Note that to use properties set by the VM, see the constraints
     * described in the initializeSystemClass method.
     */
    private static native void registerNatives();
    static {
        registerNatives();
    }
leetow2006 2018-10-26
  • 打赏
  • 举报
回复
引用 2 楼 nayi_224 的回复:
registerNatives() --> initializeSystemClass() --> setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true)); --> private static native void setOut0(PrintStream out);

应该是这个了

这个过程在哪个函数或文件里能看到?
qq_39936465 2018-10-25
  • 打赏
  • 举报
回复
system是不能被实例化的, out是静态方法可以直接被调用, println()能使用,因为println有多个方法调用,println()是其中一个无参数方法调用
nayi_224 2018-10-25
  • 打赏
  • 举报
回复
registerNatives() --> initializeSystemClass() --> setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true)); --> private static native void setOut0(PrintStream out); 应该是这个了
qybao 2018-10-25
  • 打赏
  • 举报
回复
不实例化又怎么能用? 在类加载的时候就已经实例化了,而且应该用到jni

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧