7-24 Why can the constructor be directly in the class and output directly to the console?
ws
ws 2022-09-21 11:30:56
0
1
666

class Student() {public Student (){System.out.println("This is the constructor")}}

class ConstructDemo{public static void main(String[] args){Student s =new Student();

System.out.println(s);

}} Why "This is the construction method" can be output to the console without being called in the main method

ws
ws

reply all (1)
WBOY

Because the general entry point of a Java program is the main function, execution starts from the main function. A student object is instantiated in the main function. When an object is instantiated, the constructor of this class will be called. The parameterless constructor of this class is defined in the student class, and there are output statements in the method.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!