1:
package wo;
-
public class StudentText{
public static void main(String[] args) {
Student s1=new Student(01,"张三");
Student s2=new Student(02,"李四");
boolean b=s1.equals(s2);
System.out.println(b);
}
}
class Student {
private int num;
private String nema;
public Student(int num, String nema) {
super();
this.num = num;
this.nema = nema;
}
public Student() {
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getNema() {
return nema;
}
public void setNema(String nema) {
this.nema = nema;
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
if (num != this.num)
return false;
return true;
}
}
2
package wo;
public class polyTest {
public static void main(String[] args) {
penson p=new penson("张三",25);
System.out.println(p);
loyee l=new loyee(01,3000);
System.out.println(l);
Manager m=new Manager("老师");
System.out.println(m);
}
}
class penson{
private String name;
private int age;
public penson() {
super();
}
public penson(String name,int age) {
super();
this.name=name;
this.age=age;
}
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 toString() {
return "penson [姓名:" + name + ",年龄:" + age + "]";
}
}
class loyee{
private int id;
private double salary;
public loyee() {
super();
}
public loyee(int id,double salary) {
super();
}
public int getID() {
return id;
}
public void setID(int iD) {
id = iD;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public String toString() {
return "loyee [工号" + id + ", 工资:" + salary + "]";
}
}
class Manager{
private String type;
public Manager() {
super();
}
public Manager(String type) {
super();
this.type=type;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String toString() {
return "Manager [职务名称:" + type + "]";}
}