C# Programming - Classes and Objects - Discussion

Discussion :: Classes and Objects - General Questions (Q.No.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); 

[A]. The code will not compile since we cannot explicitly use this.
[B]. Using this in this program is necessary to properly set the values in the object.
[C]. The call to SetData() is wrong since we have not explicitly passed the this reference to it.
[D]. The definition of SetData() is wrong since we have not explicitly collected the this reference.
[E]. Contents of this will be different during each call to SetData().

Answer: Option E


No answer description available for this question.

Michael said: (Jan 25, 2012)  
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.

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

Avinash said: (Nov 3, 2017)  
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.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.