public void Test(){
}
public void Test(String temp){
System.out.println(temp);
}
写法错误
应为:
public Test(){
}
public Test(String temp){
System.out.println(temp);
}
}
public void Test(String temp){
System.out.println(temp);
}
写法错误
应为:
public Test(){
}
public Test(String temp){
System.out.println(temp);
}
构造函数不应该有返回值
public void Test(){
}
public void Test(String temp){
System.out.println(temp);
}
}在你的原类文件中本来就没有一个代string参数的构造方法,你如何能调用呢!
你需要的话,可以在类定义的时候直接定义一个代参数的构造方法就是了。
}
public [void] Test(String temp){
System.out.println(temp);
}这两个构造函数中都不应该有返回类型,即使是void型也不可以,应该去掉!
public Test(){
}
public Test(String temp){
System.out.println(temp);
}
}
1. 构造函数没有返回值, public 类名(...)
2. 主类的main函数定义有错误。
class Test{
public Test(){
}
public Test(String temp){
System.out.println(temp);
}
}
public class GoGo
{
public static void main(String[] args)
{
Test i=new Test("Hello");
}
}
构造函数是没有返回值的
因为并没有定义构造函数,所以编译器会自动添加一个缺省构造函数即:
public Test(){}
所以,Test i=new Test();是可以的.
}去掉void,就可以乐。
public Test(){
}
public Test(String temp){
System.out.println(temp);
}
}
建议楼主好好的把《JAVA编程思想》多看两遍。