Consider the following program and choose the appropriate option:
import java.util.*; public class Test { public static void main(String []args) { Set<Integer> set = new LinkedHashSet<Integer>(); //#1 LinkedHashSet<Integer> set2 = new HashSet<Integer>(); //#2 SortedSet<Integer> set3 = new TreeSet<Integer>(); //#3 SortedSet<Integer> set4 = new NavigableSet<Integer>(); //#4 }/* www. jav a2 s. c o m*/ }
b)
LinkedHashSet inherits from Set so statement #1 will compile.
TreeSet inherits from SortedSet so statement #3 will also compile successfully.
LinkedHashSet is inherited from HashSet so statement #2 will not compile.
Statement #4 tries to create an object of type NavigableSet which is an interface, so it will also not compile.