GIAC
GSSP-JAVA · Question #154
GSSP-JAVA Question #154: Real Exam Question with Answer & Explanation
The correct answer is C. Friday Monday Sunday Wednesday. See the full explanation below for the reasoning.
Question
Mark works as a Programmer for InfoTech Inc. He develops the following code snippet. import java.util.*; public class DemoSet{ public static void main(String[] args){ TreeSet<String> ts = new TreeSet<String>(); ts.add("Sunday"); ts.add("Friday"); ts.add("Wednesday"); ts.add("Sunday"); ts.add("Monday"); Iterator it = ts.iterator(); while(it.hasNext()){ System.out.print(it.next() + " "); } } } What will be the output when he tries to execute the given code snippet?
Options
- AWednesday Sunday Monday Friday
- BAn exception will be thrown at runtime.
- CFriday Monday Sunday Wednesday
- DSunday Monday Wednesday Friday
Community Discussion
No community discussion yet for this question.