MCQs
What is the output of this program?
import java.util.*;
public class genericstack {
Stack stk = new Stack ();
public void push(E obj) {
stk.push(obj);
}
public E pop() {
E obj = stk.pop();
return obj;
}
}
class Output {
public static void main(String args[]) {
genericstack gs = new genericstack();
gs.push(36);
System.out.println(gs.pop());
}
}
genericstack's object gs is defined to contain a string parameter but we are sending
an integer parameter, which results in compilation error.
Output:
$ javac Output.javac
$ java Output
Hello
None.
Output:
$ javac Output.javac
$ java Output
1
None.
Output:
$ javac Output.javac
$ java Output
7.0
None.
Output:
$ javac Output.javac
$ java Output
6.0
A lower bounded wildcard is expressed using the wildcard character ('?'), following
by the super keyword, followed by its lower bound: .
None.
In generic code, the question mark (?), called the wildcard, represents an unknown type.
None.
The wildcard can be used in a variety of situations: as the type of a parameter, field, or
local variable; sometimes as a return type (though it is better programming practice to
be more specific). The wildcard is never used as a type argument for a generic
method invocation, a generic class instance creation, or a supertype.
None.