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 3 of 3.
Akmal said:
1 decade ago
@Rajeev...
why s1.Display() call default constructor since i and j in same object,s1?
why s1.Display() call default constructor since i and j in same object,s1?
Ranjana said:
1 decade ago
Here we did not use the this keyword so that it displayed null values.
Nagarjun said:
9 years ago
The keyword 'this' is missing in a method so it will come 0 and 0.0.
(1)
Snehal said:
1 decade ago
0 0 are default values set by constructor when object gets created.
Sridhar said:
7 years ago
Here; i and j will be no data so the answer is 0 and 0.
Swati mahajan said:
1 decade ago
Answer is 0 0 because not added this in SetData();.
Anomi said:
7 years ago
According to me, the result is 10 5.4.
Anurag kachhwaha said:
6 years ago
The correct answer is B.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers