近日在写一个进行自动回帖的client程序,使用了httpunit工具的webform,由于bbs上的form有onsubmit的event限制,准备overridden webform的submit方法。随后自己创建一个类去集成webform,代码如下:
/*
 * Created on 2005-6-16
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.gs.httpbbsclient;import java.io.IOException;import org.xml.sax.SAXException;import com.meterware.httpunit.SubmitButton;
import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.WebResponse;/**
 * @author harrison
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class WebFormExtends extends WebForm {
    
    /* (non-Javadoc)
     * @see com.meterware.httpunit.WebForm#doFormSubmit(com.meterware.httpunit.SubmitButton)
     */
    WebResponse doFormSubmit(SubmitButton arg0) throws IOException,SAXException {
        // TODO Auto-generated method stub
        return submitRequest( null, getRequest( arg0 ) );
    }
}
由于父类webform没有自己的构造函数(使用object的缺省构造函数),此时eclipse提示:implicit super constructor WebForm() is undefined for default constructor , must define an explicit constructor很疑惑,随后自己写了一个例子:public class aa {    public static void main(String[] args) {
    }
}================================================================public class bb extends aa {    public static void main(String[] args) {
    }
}=================================================================public class cc extends bb {    public static void main(String[] args) {
    }
}随后编译自己的验证例子,没有发现任何异常。很是疑惑,特此提出,大家讨论讨论。

解决方案 »

  1.   

    父类中如果自己定义了构造器(即如其他带参数的),那么请把不带参数的构造器写好,否则在子类中调用不带参数的构造器会出错。如果父类中没有定义构造器,那么系统会默认给它一个不带参数的构造器,子类直接super();或者不写都可以。相当于子类直接继承父类不带参数的构造器。就像你后来写的这个测试例子一样。你可以在你测试这个类aa中写另外一个构造函数
    public aa(String haha){}其他不变。
    bb就会报错了,编译你都过不去。
      

  2.   

    这个我都知道的,关键是我的WebFormExtends ,他去继承了WebForm(这个类本身使用default的构造函数),系统却提示需要定义一个显性的构造函数。
      

  3.   

    晕倒,搞错了,WebForm有构造函数,文件太长了,没看见。