publicStringToString(){return(super.toString()+"Area:"+getarea());}以上是父类里的函数,然后ComparableCircle[]circle={newComparableCircle(3),newComparableCircle(4),newComp...
public String ToString() {
return (super.toString()+" Area: "+getarea());
} 以上是父类里的函数,然后ComparableCircle[] circle= {
new ComparableCircle(3),
new ComparableCircle(4),
new ComparableCircle(5),
new ComparableCircle(6)};
java.util.Arrays.sort(circle);
for(ComparableCircle a:circle)
{
System.out.println(a.toString());
}打印的是父类的父类里的函数,如下created on Sat Oct 27 14:51:11 CST 2018
color white and filled: false 3.0
created on Sat Oct 27 14:51:11 CST 2018
color white and filled: false 4.0
created on Sat Oct 27 14:51:11 CST 2018
color white and filled: false 5.0
created on Sat Oct 27 14:51:11 CST 2018
color white and filled: false 6.0
created on Sat Oct 27 14:51:11 CST 2018
我单独创建一个对象ComparableCircle b = new ComparableCircle(5);
System.out.println(b.ToString());
打印的是:created on Sat Oct 27 14:51:11 CST 2018
color white and filled: false 5.0 Area: 78.53981633974483
展开