C# Programming - Classes and Objects - Discussion
Discussion Forum : Classes and Objects - General Questions (Q.No. 6)
6.
Which of the following will be the correct output for the C#.NET program given below?
namespace IndiabixConsoleApplication
{
class Sample
{
int i;
Single j;
public void SetData(int i, Single j)
{
i = i;
j = j;
}
public void Display()
{
Console.WriteLine(i + " " + j);
}
}
class MyProgram
{
static void Main(string[ ] args)
{
Sample s1 = new Sample();
s1.SetData(10, 5.4f);
s1.Display();
}
}
}
Discussion:
28 comments Page 1 of 3.
Anjani Kumar ray said:
1 year ago
The correct answer is C, 10 5.400000
Because setdata(10,5.4f) set data member of class, these value is displayed by function display().
Because setdata(10,5.4f) set data member of class, these value is displayed by function display().
Anurag kachhwaha said:
6 years ago
The correct answer is B.
Checos said:
6 years ago
0 0.
Because the object is created by the default constructor but the data s1. SetData (10, 5. 4f); is not created or haven't any constructor.
Because the object is created by the default constructor but the data s1. SetData (10, 5. 4f); is not created or haven't any constructor.
(1)
Anomi said:
6 years ago
According to me, the result is 10 5.4.
Sridhar said:
6 years ago
Here; i and j will be no data so the answer is 0 and 0.
Viktor said:
7 years ago
@Rajeev.
I hope you're not planning to get a job as a programmer/developer. I have read your answers under several questions and I just can't believe it's true.
I hope you're not planning to get a job as a programmer/developer. I have read your answers under several questions and I just can't believe it's true.
Nagarjun said:
8 years ago
The keyword 'this' is missing in a method so it will come 0 and 0.0.
(1)
Ravindra Maurya said:
8 years ago
It is why because we are calling same argument name, if we make its Letter Caps value will be print or it 'll be print when argument name will be different compiler is calling default constructor when we used same arguments.
Sample s1 = new Sample();
s1.SetData(10, 5.4f,8);
s1.Display();
private int i;
private Single J;
private int b;
public void SetData(int I, Single j,int B)
{
i = i;
J = j;
b = B;
}
public void Display()
{
Console.WriteLine(i + " " + J +" "+b);
}
Sample s1 = new Sample();
s1.SetData(10, 5.4f,8);
s1.Display();
private int i;
private Single J;
private int b;
public void SetData(int I, Single j,int B)
{
i = i;
J = j;
b = B;
}
public void Display()
{
Console.WriteLine(i + " " + J +" "+b);
}
(1)
David said:
9 years ago
Due to the naming collision more than having to use the this keyword as proper syntax.
Snehal said:
10 years ago
0 0 are default values set by constructor when object gets created.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers