Generics

Q1:
For the code snippet shown below, which of the following statements are valid?
public class Generic<T>
{
    public T Field; 
    public void TestSub()
    {
        T i = Field + 1;
    }
}
class MyProgram
{
    static void Main(string[] args)
    {
        Generic<int> gen = new Generic<int>();
        gen.TestSub();
    }
}

A Addition will produce result 1.

B Result of addition is system-dependent.

C Program will generate run-time exception.

D Compiler will report an error: Operator '+' is not defined for types T and int.

E None of the above.

ANS:D - Compiler will report an error: Operator '+' is not defined for types T and int.

No answer description is available. Let's discuss.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.