繁体   English   中英

'println()'是PrintStream类或实例成员函数的静态成员函数吗?

[英]Is 'println()' a static member function of PrintStream class or instance member function?

这里:

System.out.println("Hi, this is frist program");

println()PrintStream类或实例成员函数的静态成员函数吗?

正如我的老师所说:当类名后面有点( . )时,我们肯定会尝试访问该类的静态成员。

这里是静态引用变量,它引用了PrintStream类。 所以我的问题是println()函数必须是一个静态成员函数吗?

不, printlnPrintStream类的实例方法。 这是out那是一个静态成员System类。

System.out
      ^--^
        static member of the class System, returns a PrintStream instance

System.out.println(...)
          ^------^
            instance method of PrintStream

out被宣布为

public static final PrintStream out

在类System ,因此它是一个静态成员,您可以使用System.out访问它(请参阅此问题以获取final修饰符)。

println()是声明为的PrintStream类的实例方法

public void println()

不, printlnPrintStream的实例方法,您可以在PrintStream的Javadoc中看到。

void java.io.PrintStream.println(String x)

System.out为您提供了对其执行printlnPrintStream实例的引用。

println()PrintStream类的非静态 (实例)成员函数。

out是对System类中PrintStream类型的对象的静态引用。

out是一个引用, out.prinln()指的是out的实例方法。 在这种情况下, out也是另一个类的静态成员,但这对println()方法没有任何影响

这是一个实例方法。

System.out是对PrintStream实例的静态引用。 https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#out这提供了多个重载版本,如果println https://docs.oracle.com/javase/7/docs /api/java/io/PrintStream.html#println(java.lang.String)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM