1. For the code set given below,which of the following statements are perfectly valid?
a) Class MyConatiner requires that it’s type arguement must implement Icomparable interface
b) There are multiple constraints on type arguement to MyConatiner class
c) Compiler will report an error
d) None of the mentioned
2. For the code given below which statements are perfectly valid?
a) Run time exception error
b) Compile time error
c) Code run successfully and print required output
d) None of the mentioned
3. Which of given statements are valid about generics in .NET Framework?
a) generics are useful in collection classes in .NET framework
b) generics delegates are not allowed in C#.NET
c) generics is a language feature
d) All of the mentioned
e) both a and c
4. Which statement are valid for the given snippet of code:
a) Compile time error
b) Generic being a keyword cannot be used as a class name
c) run time error
d) Code runs successfully
5. Choose the output for given set of code:
a) Compile time error
b) A
c) run time error
d) Code runs successfully but prints nothing
6. Correct statement valid about generic procedures in C#.NET are?
a) All procedures in a Generic class are generic
b) Generic procedures should take at least one type parameter
c) Only those procedures labeled as Generic are Generic
d) None of the mentioned
7. For the code set given below,which of the following statements are perfectly valid?
a) Class MyConatiner requires that it’s type arguement must implement Icomparable interface
b) There are multiple constraints on type arguement to MyContainer class
c) Type arguement of class MyContainer should be Icomparable
d) None of the mentioned
8. Choose the statements which are valid for given code snippet:
a) code run successfully print nothing
b) code run successfully print 1
c) Program will give run time error
d) Compile time error
9. Which among the given class represents System.Collections.Generic namespace?
a) SortedDictionary
b) Sorted Array
c) Stack
d) Tree
e) both a and c
10. What will be the output of given code snippet?
a) Compile time error
b) Csharp
c) 0
d) Run time error
11. What will be the output of given code snippet?
a) 0
b) 30
c) Runtime Error
d) Compile time Error
12. What will be the output of given code snippet?
a) C++
b) 20
c) C++
20
d) 0
public class MyContainer<T> where T: class, IComparable
{
/* insert code here */
}
b) There are multiple constraints on type arguement to MyConatiner class
c) Compiler will report an error
d) None of the mentioned
2. For the code given below which statements are perfectly valid?
public class Csharp
{
public void subject<S>(S arg)
{
Console.WriteLine(arg);
}
}
class Program
{
static Void Main(string[] args)
{
Csharp c = new Csharp();
c.subject("hi");
c.subject(20);
}
}
b) Compile time error
c) Code run successfully and print required output
d) None of the mentioned
3. Which of given statements are valid about generics in .NET Framework?
a) generics are useful in collection classes in .NET framework
b) generics delegates are not allowed in C#.NET
c) generics is a language feature
d) All of the mentioned
e) both a and c
4. Which statement are valid for the given snippet of code:
public class Generic<T>
{
public T Field;
}
class Program
{
static void Main(string[] args)
{
Generic<String> g = new Generic<String>();
g.Field = "Hi";
Console.WriteLine(g.Field);
}
}
b) Generic being a keyword cannot be used as a class name
c) run time error
d) Code runs successfully
5. Choose the output for given set of code:
public class Generic<T>
{
public T Field;
}
class Program
{
static void Main(string[] args)
{
Generic<int> g2 = new Generic<int>();
Generic<int> g3 = new Generic<int>();
g2.Field = 8;
g3.Field = 4;
if (g2.Field % g3.Field == 0)
{
Console.WriteLine("A");
}
else
Console.WriteLine("Prints nothing:");
Console.ReadLine();
}
}
b) A
c) run time error
d) Code runs successfully but prints nothing
6. Correct statement valid about generic procedures in C#.NET are?
a) All procedures in a Generic class are generic
b) Generic procedures should take at least one type parameter
c) Only those procedures labeled as Generic are Generic
d) None of the mentioned
7. For the code set given below,which of the following statements are perfectly valid?
public class MyContainer<T> where T: IComparable
{
/* insert code here */
}
b) There are multiple constraints on type arguement to MyContainer class
c) Type arguement of class MyContainer should be Icomparable
d) None of the mentioned
8. Choose the statements which are valid for given code snippet:
public class Generic<T>
{
public T Field;
public void testSub()
{
T i = Field + 1;
}
}
class Program
{
static void Main(string[] args)
{
Generic<int>g = new Generic<int>();
g.testSub();
}
}
b) code run successfully print 1
c) Program will give run time error
d) Compile time error
9. Which among the given class represents System.Collections.Generic namespace?
a) SortedDictionary
b) Sorted Array
c) Stack
d) Tree
e) both a and c
10. 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<int> g = new Generic<int>();
g.push("Csharp");
Console.WriteLine(g.pop());
Console.ReadLine();
}
}
b) Csharp
c) 0
d) Run time error
11. 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(30);
Console.WriteLine(g.pop());
Console.ReadLine();
}
}
b) 30
c) Runtime Error
d) Compile time Error
12. 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();
}
}
b) 20
c) C++
20
d) 0