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

后端 未结 19 756
谎友^
谎友^ 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:17

    Because out is being called with the System class name itself, not an instance of a class (an object), So out must be a static variable belonging to the class System. out must be instance of a class, because it is invoking the method println().

    // the System class belongs to java.lang package
    class System {
        public static final PrintStream out;
    }
    class PrintStream {
        public void println();
    }
    
    0 讨论(0)
  • 2020-11-27 12:20

    System is a class of java.lang package, out is an object of PrintStream class and also static data member of System class, print() and println() is an instance method of PrintStream class. it is provide soft output on console.

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

    No. Actually out is a static member in the System class (not as in .NET), being an instance of PrintStream. And println is a normal (overloaded) method of the PrintStream class.

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

    Actually, if out/err/in were classes, they would be named with capital character (Out/Err/In) due to the naming convention (ignoring grammar).

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

    System is a class, that has a public static field out. So it's more like

    class System 
    {
        public static PrintStream out;
    }
    
    class PrintStream
    {
        public void println ...
    }
    

    This is a slight oversimplification, as the PrintStream class is actually in the java.io package, but it's good enough to show the relationship of stuff.

    0 讨论(0)
  • 2020-11-27 12:21
    System.out.println("Hello World");
    
    1. System: It is the name of standard class that contains objects that encapsulates the standard I/O devices of your system.

    It is contained in the package java.lang. Since java.lang package is imported in every java program by default,therefore java.lang package is the only package in Java API which does not require an import declaration.

    1. out:The object out represents output stream(i.e Command window)and is the static data member of the class System.

    So note here System.out (System -Class & out- static object i.e why its simply referred to by classname and we need not create any object).

    1. println:The println() is method of out object that takes the text string as an argument and displays it to the standard output i.e on monitor screen.

    Note
    System -Class
    out -static Object
    println() -method
    Remember a function (in java function is called method) always has the format function()

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

    System: is predefined class of java.lang package.

    out: is a static member of printStream class and its connect with console.

    Println: is a method of printstream class and its not a static.

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