一个构造
问题3)当你试着编译运行下面的代码的时候,可能会发生什么?
public class Crowle{
public static void main(String argv[]){
Crowle c = new Crowle();
}
void Crowle(){
System.out.println("Greetings from Crowle");
}
}
1) Compilation and output of the string "Greetings from Crowle"
2) Compile time error, constructors may not have a return type
3) Compilation and output of string "void"
4) Compilation and no output at runtime
------解决方案--------------------static void Crowle(){
应该就可以了
------解决方案--------------------因为void Crowle()它声明了返回值,所以它只是一个普通函数
而构造函数是【不能】声明返回值