Program prints that one of the correct answers is "It will only print : A", but it isn't correct in my case. I have tried to compile the code with javac 1.6.0_35, and I have had the runtinme exception
immediately ("A" hasn't been printed) :
Code: Select all
Exception in thread "main" java.lang.ClassCastException: Person cannot be cast to java.lang.Comparable
at java.util.TreeMap.compare(Unknown Source)
at java.util.TreeMap.put(Unknown Source)
at java.util.TreeSet.add(Unknown Source)
at StudyGroup.add(StudyGroup.java:16)
at StudyGroup.main(StudyGroup.java:21)
Line 21 in main is "mathGroup.add(new Person("MATH"));" just before printing "A" line, so ClassCastException is throwing
before program can chance of printing "A"...