What's the meaning of System.out.println in Java?

后端 未结 19 759
谎友^
谎友^ 2020-11-27 11:49

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

namespace System {
  class out {
    static println ...         


        
相关标签:
19条回答
  • 2020-11-27 12:23

    System is a class in java.lang package.

    out is the static data member in System class and reference variable of PrintStream class.

    Println() is a normal (overloaded) method of PrintStream class.

    0 讨论(0)
  • 2020-11-27 12:25

    Check following link:

    http://download.oracle.com/javase/1.5.0/docs/api/java/lang/System.html

    You will clearly see that:

    System is a class in the java.lang package.

    out is a static member of the System class, and is an instance of java.io.PrintStream.

    println is a method of java.io.PrintStream. This method is overloaded to print message to output destination, which is typically a console or file.

    0 讨论(0)
  • 2020-11-27 12:26

    println and print are the two overloaded methods which belong to the PrintStream class.

    To access them we need an instance of this class.

    A static property called out of type PrintStream is created on the System class.

    Hence to access the above methods we use the following statements:

    System.out.println("foo");
    System.out.print("foo");
    
    0 讨论(0)
  • 2020-11-27 12:26

    System - class which is final in nature. public final class System{}. Belongs to java.lang package

    out - static reference variable of type PrintStream

    println() - non static method in PrintStream class. PrintStream belongs to java.io package.

    To understand it better you can visit : How System.out.println() Works In Java

    0 讨论(0)
  • 2020-11-27 12:30
    System.out.println();
    

    System is the class

    out is a variable in the System class and it is a static and variable type is PrintStream.

    Here is the out variable in System class:

    public final static PrintStream out = null;
    

    You can see implementation of System here.

    println() is a overloaded method in PrintStream class.

    PrintStream includes three overloaded printing methods, those are:

    1. print()
    2. println()
    3. printf()

    You can see implementation of PrintStream here.

    You cannot instantiate System class and it is child class of Object and the Object is the father(superclass) of every classes including classes that you defined.

    Here is what the oracle docs says:

    public final class System extends Object

    The System class contains several useful class fields and methods. It cannot be instantiated.

    Among the facilities provided by the System class are standard input, standard output, and error output streams; access to externally defined properties and environment variables; a means of loading files and libraries; and a utility method for quickly copying a portion of an array.

    Since: JDK1.0

    If you donot know what is meant by instantiate, read this questioh. It is C# question but the concept is same.

    Also, What is the difference between an Instance and an Object?

    If you donot know what is meant by overload read this quesiotn.

    0 讨论(0)
  • 2020-11-27 12:31

    System is a class in java.lang package. And out is a PrintStream object. Nice explanation @ http://lazy-geeks.blogspot.in/2015/01/what-is-systemoutprintln.html

    0 讨论(0)
提交回复
热议问题