大佬看过来,这是构造方法的问题。这个代码可以输出结果,但是为什么会被提示有错误?
import java.lang.Enum;
enum B{a,b};
class Book{
private static int num = 0;
private String name;
private int c;
private int d;
private B type;
public B getType() {
return type;
}
public void setType(B type) {
this.type = type;
}
public Book(){
++num;
}
public Book(int d) {
System.out.print("happy");
this.d=d;
}
public int getD() {
return d;
}
public void setD(int d) {
this.d = d;
}
public Book(int c) {
this();
System.out.print("sad");
this.c=c;}
public Book(String name,int c){
this(c);
this.name = name;
System.out.print("sadsad");
}
static public int getNum(){return num;}
public int getC() {
return c;
}
public void setC(int c) {
this.c = c;
}
public void setName(String name){this.name = name;}
public String getName(){return name;}
}
class ClassMethod{
public static void main(String[] args){
System.out.println("书的总数为: " + Book.getNum() );
Book book1 = new Book("世界是平的",2);
book1.setType(B.a);
System.out.println("进了一本新书: " +B.a+book1.getType());
System.out.println("进了一本aba: " + book1.getName());
Book book2 = new Book("钢铁是怎样炼成的",3);
Book book3=new Book(23);
System.out.println("进了一本新书: "+book3.getC() + book2.getName());
System.out.println("书的总数为: " + Book.getNum());
}}