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(); } }

- Online Exam Test Papers | - MCQs[multiple choice questions and answers ] | - Mock Test Papers | - Practice Papers | - Sample Test Papers |

Question:
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();
    }
}

1.Addition will produce result 1.

2.Result of addition is system-dependent.

3.Program will generate run-time exception.

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

Posted Date:-2021-02-25 10:20:32


More MCQS Questions and answers

Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!