import java.util.*;class Z implements Comparable{??? int age;?? ?public Z(int age){?? ??? ?this.age=age;?? ?}?? ?//?? ?public boolean equals(Object obj){?? ??? ?return true;?? ?}?? ?//?? ?public int compareTo(Object obj){?? ??? ?return 1;?? ?}?? ?public class TressSetTest2{?? ?? //下面代碼在編譯時出現?? “錯誤: 內部類Z.TressSetTest2中的靜態聲明非法,???????????????????????????????????????????????? public static void main(String[] args){???????????????????????????????????????????????? public static void main(String[] args){”????? 的錯誤,當我把“static”刪除時,又出現“錯誤: 找不到或無法加載主類 TreeSetTest2”? ? ? ? public static void main(String[] args){?? ?? ??? ??? ?TreeSet set=new TreeSet();?? ??? ??? ?Z z1=new Z(6);?? ??? ??? ?set.add(z1);?? ??? ??? ?//?? ??? ??? ?System.out.println(set.add(z1));?? ??? ??? ?//?? ??? ??? ?System.out.println(set);?? ??? ??? ?//?? ??? ??? ?((Z)(set.first())).age=9;?? ??? ??? ?//?? ??? ??? ?System.out.println(((Z)(set.last())).age);?? ??? ?}?? ?}}
添加回答
舉報
0/150
提交
取消