下面代码:要求重写方法,搞了好久没搞出帮个忙classStudentextendsjava.lang.Object{privateStringmName;privateintmAge;privateStringmSex;publicStudent(Stringname,intage,String...
下面代码: 要求重写方法,搞了好久没搞出帮个忙class Student extends java.lang.Object{ private String mName; private int mAge; private String mSex; public Student(String name, int age, String sex) { mName = name; mAge = age; mSex = sex;}public String getMName() { return mName;}public void setMName(String name){ mName = name;}public int getMAge() { return mAge;}public void setMAge(int age) { mAge = age;}public String getMSecx() { return mSex;}public void setMSecx(String secx){ mSex = secx;}public String toString(){ return "姓名是:"+this.mName+",性别是:"+this.mSex+",年龄是:"+this.mAge;}public boolean equals(Object obj){ if() { return true; } else { return false; }}}/**测试类*/public class StudentTest { public static void main(String[] args) { Student std =new Student("张三",19,"男"); Student std1 =new Student("张三",19,"男"); if(std.equals(std)) { System.out.println("相同的对象"); } else { System.out.println("不同的对象"); } System.out.println(std); System.out.println(std1); }}
展开