C# Programming - Constructors - Discussion

Discussion Forum : Constructors - General Questions (Q.No. 6)
6.
Which of the following is the correct way to define the constructor(s) of the Sample class if we are to create objects as per the C#.NET code snippet given below?
Sample s1 = new Sample(); 
Sample s2 = new Sample(9, 5.6f);
public Sample()
{
    i = 0; 
    j = 0.0f;
}
public Sample (int ii, Single jj)
{
    i = ii;
    j = jj;
}
public Sample (Optional int ii = 0, Optional Single jj = 0.0f)
{
    i = ii;
    j = jj;
}
public Sample (int ii, Single jj)
{
    i = ii;
    j = jj;
}
Sample s;
s = new Sample();
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
5 comments Page 1 of 1.

Veena Mullapudi said:   6 years ago
C is also correct right, it is parameterized constructor.

Jaya said:   10 years ago
A is correct because first one is default constructor and second is parameterized constructor.

Rohan Jadhav said:   1 decade ago
'A' is correct because there is only default constructor and other is parametrized constructor.

Rajeev said:   1 decade ago
To create object of Simple class like--

Sample s1 = new Sample();


one should create constructor without parameters which is like this --
public Sample()
{
i = 0;
j = 0.0f;
}

and for
Sample s2 = new Sample(9, 5.6f);

constructor should contain two parameters of type int and Single respectively . so --
public Sample (int ii, Single jj)
{
i = ii;
j = jj;
}

Malathisachu said:   1 decade ago
We are having 2 creation of object with values, . It describe 1 is default constructor and than parameterised constructor. We can declare two method to accept each object.

Post your comments here:

Your comments will be displayed after verification.