主题:父类使用子类的构造函数
public class Test {
public static void main(String[] args) {
[color=FF0000]Object circle1 = new Circle();[/color]
Object circle2 = new Circle();
Circle circle3 = new Circle();
Circle circle4 = new Circle();
System.out.println(circle1.equals(circle2));
System.out.println(circle3.equals(circle4));
System.out.println(circle1.equals(circle3));
System.out.println(circle3.equals(circle1));
}
}
class Circle {
double radius;
//equals方法从载
public boolean equals(Circle circle) {
System.out.println("user equals about Circle!");
return this.radius == circle.radius;
}
//equals方法覆盖(是覆盖父类Object的equals方法)
public boolean equals(Object circle) {
System.out.println("user equals about Object!");
return this.radius==((Circle)circle).radius;
}
}
那位能帮忙解释下红色字体那一句?
public static void main(String[] args) {
[color=FF0000]Object circle1 = new Circle();[/color]
Object circle2 = new Circle();
Circle circle3 = new Circle();
Circle circle4 = new Circle();
System.out.println(circle1.equals(circle2));
System.out.println(circle3.equals(circle4));
System.out.println(circle1.equals(circle3));
System.out.println(circle3.equals(circle1));
}
}
class Circle {
double radius;
//equals方法从载
public boolean equals(Circle circle) {
System.out.println("user equals about Circle!");
return this.radius == circle.radius;
}
//equals方法覆盖(是覆盖父类Object的equals方法)
public boolean equals(Object circle) {
System.out.println("user equals about Object!");
return this.radius==((Circle)circle).radius;
}
}
那位能帮忙解释下红色字体那一句?