Why does System.out.println have to be inside a method?

后端 未结 6 1551
借酒劲吻你
借酒劲吻你 2020-12-11 07:26
class Employee {    
    int DOB;
    int eid;
    String name;
    double salary;
    System.out.println(\"Employee class\");
}

If I write the

6条回答
  •  半阙折子戏
    2020-12-11 07:59

    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.

    out is the standard output stream and println is the method.

    You can't just run code outside of a method unless it's a variable/constant declaration, a class declaration

提交回复
热议问题