What's the meaning of System.out.println in Ja

2019-01-05 10:24发布

Is this static println function in out class from System namespace?

namespace System {
  class out {
    static println ...
  }

How can I interpret this name? And where in JRE this function is defined? In java.lang.System/java.lang.Object?

20条回答
别忘想泡老子
2楼-- · 2019-01-05 11:12

No. Actually out is a static member in the System class (not as in .NET), being an instance of PrintStream. And println is a normal (overloaded) method of the PrintStream class.

See http://download.oracle.com/javase/6/docs/api/java/lang/System.html#out.

Actually, if out/err/in were classes, they would be named with capital character (Out/Err/In) due to the naming convention (ignoring grammar).

查看更多
女痞
3楼-- · 2019-01-05 11:13

Because out is being called with the System class name itself, not an instance of a class (an object), So out must be a static variable belonging to the class System. out must be instance of a class, because it is invoking the method println().

// the System class belongs to java.lang package
class System {
    public static final PrintStream out;
}
class PrintStream {
    public void println();
}
查看更多
登录 后发表回答