Does the System.out object belong to class System or class PrintStream? [closed]

我怕爱的太早我们不能终老 提交于 2019-12-01 08:32:18

"out" belongs to class "System" and is of type "PrintStream" :)

Marko Topolnik

It depends what you mean by "belongs to".

Usually, people would say out "belongs" to System because it is a static field declared in that class. Note, though, that this concept of belonging is only a weak one, basically implying only a namespace ownership. There is no special relation between a class and its static fields.

You may also say the object referred to by the out variable belongs to the PrintStream class because it is an instance of that class (or a subclass), just as "beagle" belongs to the "dog" class. This is not standard usage in Java parlance, but it makes perfect sense from the perspective of type theory, where a type is really a set of values, and the value of out "belongs" to that the type / set defined by the PrintStream class.

It is defined as:

static PrintStream  out 

out is a static field in System. Its type is PrintStream.

System.out is a PrintStream object. It is defined in System (so, it is member of System) class as :

static PrintStream out

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

In loose simple terms, 'out' is a field (i.e. an object) in class 'System' of type 'PrintStream'.

Out is the static reference variable in class System and is of PrintStream(class) type.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!