MyException - 我的异常网
当前位置:我的异常网» J2SE » 生手学习 编译后提示找不到符号 构造函数StudentV5

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

www.MyException.Cn  网友分享于:2013-12-15  浏览:112次
新手学习 编译后提示找不到符号 构造函数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());
……

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有