public class Main {/* from 时代Java - nowjava.com*/
public double add(int a, int b) {
System.out.println("Inside add(int a, int b)");
double s = a + b;
return s;
}
public double add(double a, double b) {
System.out.println("Inside add(double a, double b)");
double s = a + b;
return s;
}
public void test(Employee e) {
System.out.println("Inside test(Employee e)");
}
public void test(Manager e) {
System.out.println("Inside test(Manager m)");
}
/*来自 nowjava.com - 时 代 Java*/
public static void main(String[] args) {
Main ot = new Main();
int i = 10;
int j = 15;
double d1 = 1.4;
double d2 = 2.5;
float f1 = 1.3F;
float f2 = 1.5F;
short s1 = 2;
short s2 = 6;
ot.add(i, j);
ot.add(d1, j);
ot.add(i, s1);
ot.add(s1, s2);
ot.add(f1, f2);
ot.add(f1, s2);
Employee emp = new Employee();
Manager mgr = new Manager();
ot.test(emp);
ot.test(mgr);
emp = mgr;
ot.test(emp);
}
}
class Employee {
private String name = "Unknown";
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public boolean equals(Object obj) {
boolean isEqual = false;
// We compare objects of the Employee class with the objects of
// Employee class or its descendants
if (obj instanceof Employee) {
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。