Exercise: Constructors

Questions for: Constructors

Which of the following statements are correct about the C#.NET code snippet given below?
class Sample
{
    static int i;
    int j;
    public void proc1()
    {
        i = 11; 
        j = 22;
    }
    public static void proc2()
    {
        i = 1;
        j = 2;
    }
    static Sample()
    {
        i = 0; 
        j = 0;
    }
}
A:
i cannot be initialized in proc1().
B:
proc1() can initialize i as well as j.
C:
j can be initialized in proc2().
D:
The constructor can never be declared as static.
Answer: B
No answer description is available. Let's discuss.
Is it possible to invoke Garbage Collector explicitly?
A:
Yes
B:
No
C:
D:
Answer: A
No answer description is available. Let's discuss.
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.
Answer: B
No answer description is available. Let's discuss.
Which of the following statements are correct about constructors in C#.NET?
  1. Constructors cannot be overloaded.
  2. Constructors always have the name same as the name of the class.
  3. Constructors are never called explicitly.
  4. Constructors never return any value.
  5. Constructors allocate space for the object in memory.
A:
1, 3, 5
B:
2, 3, 4
C:
3, 5
D:
4, 5
Answer: B
No answer description is available. Let's discuss.
Can static procedures access instance data?
A:
Yes
B:
No
C:
D:
Answer: B
No answer description is available. Let's discuss.
Ad Slot (Above Pagination)
Quiz