class test_1{
test_1(){
System.out.println("jijiji");
}
System.out.println("jijiji");
}
public class Main {
public static void main(String[] args) {
test_1 test = new test_1();
}
}
In the test_1
class, the print statement in the constructor test_1()
did not report an error, but its next line reported an error and showed that an identifier is required.
Could you please explain this What is the reason? Java's System.out.println()
must be used in method?
This class itself is composed of methods and objects. What you print is actually the method body, so it must be placed in the method