A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

本帖最后由 徐小骥 于 2012-8-4 16:54 编辑

        
public class test{
class Student{
        private String name;
        private int age;
        private int achievement;
      
public Student (String name,int age,int achievement){
                this.name=name;
                this.age=age;
                this.achievement=achievement;
        }
         ...
}
public static void main(String[] args){
        new Student("张三","2","87");//这代码提示:The constructor test10.Student(String, String, String) is undefined
         ...
         ...
}
}
我构造的函数是Student(String, int, int) ,插入的数据是 String, int, int ,编译的时候提示找不到 构造函数Student(String, String, String)
这是怎么回事?我输入的是int类型,没输入String啊!!



评分

参与人数 1技术分 +1 收起 理由
张_涛 + 1 新人报道,赞一个!

查看全部评分

8 个回复

正序浏览
张扬123 发表于 2012-8-4 00:31
public class test{
class Student{
        private String name;

谢谢 已经解决了
回复 使用道具 举报
public class test{
class Student{
        private String name;
        private int age;
        private int achievement;
      
public Student (String name,int age,int achievement){ 这里是String ,int, int的参数
                this.name=name;
                this.age=age;
                this.achievement=achievement;
        }
         ...
}
public static void main(String[] args){
        new Student("张三","2","87");但是你传进来的都是String类型的。把2和87上面的双引号去掉。
         ...
         ...
}
}
回复 使用道具 举报
问题已解决
回复 使用道具 举报
林康春 发表于 2012-8-4 00:17
public static void main(String[] args){
        new Student("张三","2","87");//这代码提示:The const ...

是的,问题已经解决了。。。发帖之后才看清楚。。奋斗到眼花了
回复 使用道具 举报
王志明 发表于 2012-8-4 00:15
class Student{
        private String name;
        private int age;

我找到原因了。。粗心了
回复 使用道具 举报
public static void main(String[] args){
        new Student("张三","2","87");//这代码提示:The constructor test10.Student(String, String, String) is undefined
         ...
         ...
}
new Student("张三","2","87");这里的 2 ,87 被你写成字符串拉
那肯定错了嘛
回复 使用道具 举报
本帖最后由 余明辉 于 2012-8-4 00:22 编辑

new Student("张三","2","87"); 这里错了
应该是 new Student("张三", 2, 87);  你加了双引号,就代表传递进去的是String,不是int了

通过编译时的错误提示 :编译的时候提示找不到 构造函数Student(String, String, String)
就说明编译器找不到Student(String, String, String)这样的构造方法,因为你传了3个字符串进去,它就找3个参数都是String的构造方法,但是你没有定义,所以编译就错了

还有这句错误提示:The constructor test10.Student(String, String, String) is undefined  
constructor 构造方法的意思,
undefined 没找到
翻译过来就是 构造方法
Student(String, String, String)没找到
这个时候你就要想了,我定义了啊,为什么它提示找这样的构造方法呢,然后你再回头去看下你传的参数,就能发现错误了

一定要学会看错误提示,慢慢学会看它,错误提示是我们的朋友,不要怕它,因为它能帮我们及时发现错误出在哪里,省去好多我们查错误的时间

希望可以帮你到。
回复 使用道具 举报
class Student{
        private String name;
        private int age;
        private int achievement;
      
public Student (String name,int age,int achievement){
                this.name=name;
                this.age=age;
                this.achievement=achievement;
        }
}
public static void main(String[] args){
        // 你传入的参数的类型和构造器参数类型不一致
        new Student("张三","2","87");//这代码提示:The constructor test10.Student(String, String, String) is undefined
}

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马