Question: 1. Create java files to make this code compile and run. 2. What five objects are created in the main? 3. Can you spot the

1. Create java files to make this code compile and run.

2. What five objects are created in the main?

3. Can you spot the comparator constructor call? Where is the class definition for the comparator?

1. Create java files to make this code compile and run. 2.

package dog; import java.utiL.ArrayList; import java.util.Collections; import java.utiL.Comparator; import java.util.List; public class MyCompara3 i public static void main(String[ args)i List dogs = new ArrayList0; dogs.add(new Dog("Fido", 4)); dogs.add(new Dog(" Fido", 3)); dogs.add(new Dog("Alfie", 4)); System. out.println(dogs); Collections.sort(dogs, new ComparatorO @Override public int compare(Animal a, Animal b)i return a.getLegs) - b.getLegsQ; X) System. out.println(dogs); Collections.sort(dogs); System. out.println(dogs)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!