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
WBOY2022-09-21 17:57:14
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.