constructors programing questions

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);

A.

public Sample()
{
i = 0;
j = 0.0f;
}
public Sample (int ii, Single jj)
{
i = ii;
j = jj;
}

B.

public Sample (Optional int ii = 0, Optional Single jj = 0.0f)
{
i = ii;
j = jj;
}

C.

public Sample (int ii, Single jj)
{
i = ii;
j = jj;
}

D.

Sample s;

E.

s = new Sample();

Answer & Explanation

Answer: Option A

Explanation:

No answer description available for this question. Let us discuss.
View Answer Workspace Report Discuss in Forum
7.

In which of the following should the methods of a class differ if they are to be treated as overloaded methods?

Type of arguments
Return type of methods
Number of arguments
Names of methods
Order of arguments

A.     2, 4
B.     3, 5
C.     1, 3, 5
D.     3, 4, 5
Answer & Explanation

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.
View Answer Workspace Report Discuss in Forum
8.

Can static procedures access instance data?
A.     Yes    B.     No
Answer & Explanation

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.
View Answer Workspace Report Discuss in Forum
9.

Which of the following statements are correct about constructors in C#.NET?

Constructors cannot be overloaded.
Constructors always have the name same as the name of the class.
Constructors are never called explicitly.
Constructors never return any value.
Constructors allocate space for the object in memory.

A.     1, 3, 5
B.     2, 3, 4
C.     3, 5
D.     4, 5
E.     None of these
Answer & Explanation

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.
View Answer Workspace Report Discuss in Forum
10.

How many times can a constructor be called during lifetime of the object?
A.     As many times as we call it.
B.     Only once.
C.     Depends upon a Project Setting made in Visual Studio.NET.
D.     Any number of times before the object gets garbage collected.
E.     Any number of times before the object is deleted.
Answer & Explanation

Answer: Option B

Explanation:

No answer description available for this question.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top