[英]Is 'println()' a static member function of PrintStream class or instance member function?
Here: 这里:
System.out.println("Hi, this is frist program");
Is println()
a static member function of PrintStream
class or instance member function? println()
是PrintStream
类或实例成员函数的静态成员函数吗?
As told by my teacher : that when there is dot ( .
) after class name then definitely we are trying to access the static member of the class. 正如我的老师所说:当类名后面有点( .
)时,我们肯定会尝试访问该类的静态成员。
As here out is static reference variable and it has reference of PrintStream class. 这里是静态引用变量,它引用了PrintStream类。 So my question is that is the println()
function has necessarily to be a static member function? 所以我的问题是println()
函数必须是一个静态成员函数吗?
No, println
is an instance method of the PrintStream
class. 不, println
是PrintStream
类的实例方法。 It is out
that is a static member of the System
class. 这是out
那是一个静态成员System
类。
System.out
^--^
static member of the class System, returns a PrintStream instance
System.out.println(...)
^------^
instance method of PrintStream
public static final PrintStream out
in the class System
, so it is a static member and you access it with System.out
(refer to this question for the final
modifier). 在类System
,因此它是一个静态成员,您可以使用System.out
访问它(请参阅此问题以获取final
修饰符)。
println()
is an instance method of the PrintStream
class declared as println()
是声明为的PrintStream
类的实例方法
public void println()
No, println
is an instance method of PrintStream
, as you can see in the Javadoc of PrintStream
. 不, println
是PrintStream
的实例方法,您可以在PrintStream
的Javadoc中看到。
void java.io.PrintStream.println(String x) void java.io.PrintStream.println(String x)
System.out
gives you a reference to a PrintStream
instance for which println
is executed. System.out
为您提供了对其执行println
的PrintStream
实例的引用。
println()
is a non static (instance) member function of PrintStream
class. println()
是PrintStream
类的非静态 (实例)成员函数。
out
is a static reference to an object of type PrintStream
, inside System
class. out
是对System
类中PrintStream
类型的对象的静态引用。
out
is a reference, out.prinln()
refers to the instance method of out
. out
是一个引用, out.prinln()
指的是out
的实例方法。 In this case out
is also a static member of another class, but this doesn't make any difference to the println()
method 在这种情况下, out
也是另一个类的静态成员,但这对println()
方法没有任何影响
It's an instance method. 这是一个实例方法。
System.out
is a static reference to a PrintStream
instance. System.out
是对PrintStream
实例的静态引用。 https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#out and this provides multiple overloaded versions if println
https://docs.oracle.com/javase/7/docs/api/java/io/PrintStream.html#println(java.lang.String) 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.