4) What will be the output of the following program?
package navset; import java.util.TreeSet; public class Ques02 { public static void main(String[] args) { MyNavigableSet objects = new MyNavigableSet(); objects.add(new Object()); System.out.println(objects); } } class MyNavigableSet extends TreeSet<String>{ public boolean add(Object value){ return super.add(value); } }
- The program will compile and run fine to print the contents of the set.
- The program will raise a run-time exception telling that it is not possible to add objects of type ‘java.lang.Object’ in place of ‘java.lang.String’.
- The program will raise a compile-time error.
Answer
4) c.
A compile-time error telling that a name-clash has happened for the overridden method taking Object as argument.