Originally posted by Hassel: what is the final output of the following code. explain how it happens? ...
This will not even compile. First, the Person class does not have a constructor that takes a single String as an argument. Second, the compareTo(Object o) method is declared to return an int, but has no implementation. And third, the ArrayList takes Strings, so trying to add instances of Person will not work.
Supposing you added the constructor, provided (proper) implementation for the compareTo method, and changed the ArrayList type to Person, then the code will compile, but... The output won't tell you much, because the Person class has not overridden Object's toString method, so you will only see "cryptic" representations of instances.
Where did this code come from?
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org