Question
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();
}
}
a.
Compile time error
b.
Csharp
c.
0
d.
Run time error
Posted under C# programming
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?
Similar Questions
Discover Related MCQs
Q. Which of these type parameters is used for generic methods to return and accept any type of object?
View solution
Q. Which of these is a correct way of defining generic method?
View solution
Q. Which among the given classes is present in System.Collection.Generic.namespace?
View solution
Q. Select the type argument of an open constructed type?
View solution
Q. What does the following code set defines?
public Gen(T o)
{
ob = o;
}
View solution
Q. What does the following code block defines?
class Gen<T>
{
T ob;
}
View solution
Q. Choose the advantages of using generics?
View solution
Q. Are generics in C# are same as the generics in java and templates in C++?
View solution
Q. What is meant by the term generics?
View solution
Q. Select the modifiers which control the accessibility of the delegate:
View solution
Q. Incorrect statements about delegates are?
View solution
Q. Which of the following are the correct statements about delegates?
View solution
Q. Choose the statements which makes delegate in C#.NET different from a normal class?
View solution
Q. Which of the following statements is correct about a delegate?
View solution
Q. Choose the incorrect statement about delegates?
View solution
Q. Which among the following differentiates a delegate in C#.NET from a conventional function pointer in other languages?
View solution
Q. Which of the following is an incorrect statement about delegate?
View solution
Q. Which among the following is the correct statement about delegate declaration ?
delegate void del(int i);
View solution
Q. Choose the incorrect statement among the following about the delegate?
View solution
Q. To generate a simple notification for an object in runtime, the programming construct to be used for implementing this idea?
View solution
Suggested Topics
Are you eager to expand your knowledge beyond C# programming? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!