adplus-dvertising
frame-decoration

Question

What will be the output of the given code snippet?
public class Generic<T>
{
    Stack<T> stk = new Stack<T>();
    public void push(T obj)
    {
        stk.Push(obj);
    }
    public T pop()
    {
        T obj = stk.Pop();
        return obj;
    }
}
class Program
{
    static void Main(string[] args)
    {
        Generic<int> g = new Generic<int>();
        g.push("Csharp");
        Console.WriteLine(g.pop());
        Console.ReadLine();
    }
}public class Generic<T>
{
    Stack<T> stk = new Stack<T>();
    public void push(T obj)
    {
        stk.Push(obj);
    }
    public T pop()
    {
        T obj = stk.Pop();
        return obj;
    }
}
class Program
{
    static void Main(string[] args)
    {
        Generic<string> g = new Generic<string>();
        g.push(30);
        Console.WriteLine(g.pop());
        Console.ReadLine();
    }
}

a.

0

b.

30

c.

Runtime Error

d.

Compile time Error

Answer: (b).30

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What will be the output of the given code snippet?