public class Student {
private String name;//alter+shift+r bian liang gaiming
private int age;
private String sex;
public Student() {
super();
}
public Student(String name, int age, String sex) {
super();
this.age = age;
this.name = name;
this.sex = sex;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
//public void method(){}
//Scanner sc=new Scanner(System.in);
public void show() {
}
//@Override
/*public String toString() {
return name1+age+sex;
}*/
@Override
public String toString() {
return "Student [name1=" + name + ", age=" + age + ", sex=" + sex
+ "]";
}
@Override
public boolean equals(Object obj) {//注意重写方法的时候注意向下转型的问题
Student s=(Student)obj;
return this.name.equals(s.name)&&this.age==age&&this.sex.equals(s.sex);//数值的比较用==。。。
}
}
package day11;
import day111.Student11;
public class FirstDemo {
public static void main(String[] args) {
Student s = new Student("张三", 23, "男");
System.out.println(s.getName() + ".." + s.getAge() + ".." + s.getSex());
Student11 ss = new Student11();
System.out.println(s.hashCode());
Class c = s.getClass();
String str = c.getName();
System.out.println(str);
System.out.println(s.toString());
Student w = new Student("张三", 23, "男");
Student ww = new Student("张三", 23, "男");
System.out.println(w.equals(ww));
}
}
|
|