In Java, can System.out.println be used only in method?
PHP中文网
PHP中文网 2017-05-27 17:41:48
0
1
615
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?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
给我你的怀抱

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template