Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System and out in java

Tags:

java

I am new java user. Recently I have learned that out (Which we use at System.out.println) is a java standard output object.

My question is; I never created this object by myself or haven't found any code which creates this object. So how it is accessible to use?

And more over I think System is a class name. If so, is out a static member of the System class, since we are accessing out without creating a new object of System class?

like image 809
Mehmood Arbaz Avatar asked Mar 20 '15 01:03

Mehmood Arbaz


3 Answers

Yes, System is a class and out is a static member variable of that class.

public final class System {
    public static final PrintStream out = ...;
    public static final PrintStream err = ...;
    public static final InputStream in = ...;
    ...
}

See the Java documentation for System class

like image 84
Jason Avatar answered Nov 14 '22 21:11

Jason


yep, this lives on the System object:

public final static PrintStream out = null;
like image 27
Derek_M Avatar answered Nov 14 '22 23:11

Derek_M


A good way to learn a language (and to have the right answers) is to look at the API source. in System.java

...
public final static PrintStream out = null;
...

you don't need to create object in order to access static members

like image 43
Luigi Cortese Avatar answered Nov 14 '22 21:11

Luigi Cortese