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

后端 未结 6 1549
借酒劲吻你
借酒劲吻你 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 08:12

    when it would be inside a class, but outside of any method, you cannot call it, you have to create method for example getData() and calling

    Employee e = new Employee().getData();
    

    properly writes your message.

提交回复
热议问题