-
What is the output of this program?
import java.util.*;
class genericstack
{
Stackobject = new Stack ();
public void push(E obj)
{
object.push(obj);
}
public E pop()
{
E obj = object.pop();
return obj;
}
}
public class Output
{
public static void main(String args[])
{
genericstackgenericstackObj = new genericstack ();
genericstackObj.push("Interview Mania");
System.out.println(genericstackObj.pop());
}
}
-
- Interview Mania
- Mania
- Interviiw
- Compilation Error
- Runtime Error
Correct Option: D
genericstack’s object genericstackObj is defined to contain a integer parameter but we are sending an string parameter, which results in compilation error.
utput.java:21: error: incompatible types: String cannot be converted to Integer
genericstackObj.push("Interview Mania");
^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error