class M {
M() {
System.out.println("Hello world!");
}
public static void main(String[] args) {
M m = new M();
}
}
问题:请问结果为什么会输出“Hello world!”,在main中我只是创建了一个对象,并没有使用该对象,怎么会执行输出语句
呢?
请各位高手指点,我这是哪个知识点没掌握好,谢谢。
...全文
655518打赏收藏
java 构造函数什么时候被调用执行
class M { M() { System.out.println("Hello world!"); } public static void main(String[] args) { M m = new M(); } } 问题:请问结果为什么会输出“Hello world!”,在main中我只是创建了一个对象,并没有使用该对象,怎么会执行输出语句 呢? 请各位高手指点,我这是哪个知识点没掌握好,谢谢。