C# Programming - Classes and Objects - Discussion

Discussion Forum : Classes and Objects - General Questions (Q.No. 15)
15.
Which of the following statements are correct about the C#.NET code snippet given below?
namespace IndiabixConsoleApplication
{ 
    class Sample
    { 
        int i, j; 
        public void SetData(int ii, int jj)
        {
            this.i = ii;
            this.j = jj 
        } 
    } 
    class MyProgram
    { 
        static void Main(string[ ] args)
        { 
            Sample s1 = new Sample(); 
            s1.SetData(10, 2); 
            Sample s2 = new Sample(); 
            s2.SetData(5, 10); 
        } 
    } 
}
The code will not compile since we cannot explicitly use this.
Using this in this program is necessary to properly set the values in the object.
The call to SetData() is wrong since we have not explicitly passed the this reference to it.
The definition of SetData() is wrong since we have not explicitly collected the this reference.
Contents of this will be different during each call to SetData().
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
4 comments Page 1 of 1.

Michael said:   1 decade ago
That answer is kind of misleading actually. It doesn't adequately describe the nature of the condition. Different how? During each call to SetData()? Logically, this answer doesn't necessarily follow, except by way of elimination of the other (obviously) false answers.

Avinash said:   8 years ago
whenever we calling to method setdata repetadely it modifying class level variable inside method[
[( this.i ) and (this.j)] every time .
Hence answer is 5.

Yakesh said:   1 decade ago
Just write the statement
Console.WriteLine(i+" "+j);
Will get the o/p:
10 2
5 10
Hence option 5 is correct

Ibm said:   3 years ago
Hi All.

SetData Creates a compiler error because this.j = jj is missing the `;`.

Post your comments here:

Your comments will be displayed after verification.