首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

生手学习 编译后提示找不到符号 构造函数StudentV5(Sting,string ,int)

2011-12-14 
新手学习 编译后提示找不到符号 构造函数StudentV5(Sting,string ,int)public class II{public staticvoid

新手学习 编译后提示找不到符号 构造函数StudentV5(Sting,string ,int)
public class II{
public static void main(String args[])
  {
  StudentV5 s1=new StudentV5("laoda","M",21);

System.out.println(s1);
   
 }

}
class StudentV5{
private String Name;

private String Sex;
  private byte Grade;
  public StudentV5(String name,String sex,byte grade)
{ System.out.println("初始化!————");
Setname(name);
Setgrade(grade);
Setsex(sex);
}
  public void Setname(String name){ Name=name; }
  public void Setgrade(byte grade) { Grade=grade;}
  public void Setsex(String sex) { Sex=sex;}
   

}

[解决办法]
把Grade的类型改成int类型就行

Java code
package csdn;public class StudentTest {    public static void main(String args[]) {        StudentV5 s1 = new StudentV5("laoda", "M", 21);        System.out.println(s1); // 在没有重写toString的情况下,这个打印的是 该对象在内存中的唯一标识,由对象名+散列码组成的    }}class StudentV5 {        private String Name; // 变量开头字母为小写 如:name    private String Sex;    private int Grade;    public StudentV5(String name, String sex, int grade) {         System.out.println("初始化!————");        Setname(name); // 初始化不必这样 直接 this.name = name        Setgrade(grade);        Setsex(sex);    }    public void Setname(String name) {        Name = name;    }    public void Setgrade(int grade) {        Grade = grade;    }    public void Setsex(String sex) {        Sex = sex;    }}
[解决办法]
sorry啊,我2楼的那个是错的,没编译就提上来了
Java code
package com.snbc.study;public class Student {        private int grade;        private String name;        private String gender;        public int getGrade() {        return grade;    }    public void setGrade(int grade) {        this.grade = grade;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public String getGender() {        return gender;    }    public void setGender(String gender) {        this.gender = gender;    }    public void addStudent(int grade, String name,String gender){        setName(name);        setGender(gender);        setGrade(grade);    }    }
[解决办法]
探讨
Java code


public class Doit{
public static void main(String args[])
{
StudentV5 s1=new StudentV5("laoda","M",21);

System.out.println(s1.getName()+'\t'+s1.getSex()+'\t'+s1.getGrade());
……

热点排行