package com.ceniao.constructor;public class ConstructorTest {
private ConstructorTest ct = new ConstructorTest(); public static void main(String[] args) {
ConstructorTest c = new ConstructorTest(); }}
运行会报错,请大侠们解释一下,我自己没分析出来 。
private ConstructorTest ct = new ConstructorTest(); public static void main(String[] args) {
ConstructorTest c = new ConstructorTest(); }}
运行会报错,请大侠们解释一下,我自己没分析出来 。
楼主【chenniaoc】截止到2008-07-16 15:07:30的历史汇总数据(不包括此帖):
发帖的总数量:5 发帖的总分数:100 每贴平均分数:20
回帖的总数量:32 得分贴总数量:4 回帖的得分率:12%
结贴的总数量:4 结贴的总分数:80
无满意结贴数:0 无满意结贴分:0
未结的帖子数:1 未结的总分数:20
结贴的百分比:80.00 % 结分的百分比:80.00 %
无满意结贴率:0.00 % 无满意结分率:0.00 %
楼主加油
public class ConstructorTest {
private static ConstructorTest ct = new ConstructorTest();public static void main(String[] args) {
ConstructorTest c = new ConstructorTest();}} 你改成这样因为你一直在创建新对象,所以出问题了
而执行这句话的时候又是创建一个新实例,还是要执行new ConstructorTest();
就会初始化private ConstructorTest ct = new ConstructorTest(); 你是翻来覆去的new ConstructorTest();
package com.ceniao.constructor; public class ConstructorTest { private ConstructorTest ct = new ConstructorTest(); public static void main(String[] args) { ConstructorTest c = new ConstructorTest(); //new ConstructorTest() 后会调用默认的构造方法!而构造方法会初试所有属性!
//当碰到private ConstructorTest ct = new ConstructorTest(); 然后又会继续调用构造方法!一直不停的这样下去会不出错误?} }