adplus-dvertising
frame-decoration

Question

What will be the output of 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<string> g = new Generic<string>();
        g.push("C++");
        Console.WriteLine(g.pop() + " ");
        Generic<int> g1 = new Generic<int>();
        g1.push(20);
        Console.WriteLine(g1.pop());
        Console.ReadLine();
    }
}

a.

C++

b.

20

c.

C++
20

d.

0

Posted under C# programming

Answer: (c).C++
20

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 given code snippet?