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); } }
------解决方案--------------------