/**
 * @author Administrator
 * 
 */
public class Question8 {

String title;
int value;

public Question8() {
this.title += " world.";
}

public Question8(int value) {
this.value = 5;
this.title = "hello";

// ERROR
Question8();
} /**
 * @param args
 */
public static void main(String[] args) {

Question8 question8 = new Question8(5); System.out.println(question8.title);
}}这样的调用会在ERROR哪里报错,编译不通过
请问有什么问题?
该如何调用?

解决方案 »

  1.   

    构造函数中调用构造函数应该是用this关键字,将Question8();改为this();
      

  2.   

    构造函数调用本类其它构造函数用this()关键字调用。
    调用父类构造函数用super()构造函数。
    而且这两个必须放在构造函数第一行。
      

  3.   

    public class Question8 {
        
        String title;
        int value;
        
        public Question8() {
            this.title += " world.";
        }
        
        public Question8(int value) {
         super();
            this.value = 5;
            this.title = "hello";
            
            // ERROR
            
        }    /**
         * @param args
         */
        public static void main(String[] args) {
            
            Question8 question8 = new Question8(5);        System.out.println(question8.title);
        }}
    可以了啊