super();
this.name = name;
this.age = age;
}
public Student()
{
super();
}
//重写hashcode
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + age;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
//从写equals 方法
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (this.getClass() != obj.getClass())
return false;
Student other = (Student) obj;
if (age != other.age)
return false;
if (name == null)
{
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
//重写toString方法
@Override
public String toString()
{
String string= this.name +" "+this.age;
return string;
}
public void chi()
{
System.out.println("吃了一顿饭");
}
public void chi(int a)
{
System.out.println("吃了一顿饭"+a);
}
}
|