C# Programming :: Constructors
-
Which of the following statements is correct?
-
Which of the following statements is correct about the C#.NET code snippet given below?
namespace FreshergateConsoleApplication { class Sample { public int func() { return 1; } public Single func() { return 2.4f ; } } class Program { static void Main(string[ ] ars) { Sample s1 = new Sample(); int i; i = s1.func(); Single j; j = s1.func(); } } }
-
Which of the following ways to create an object of the Sample class given below will work correctly?
class Sample { int i; Single j; double k; public Sample (int ii, Single jj, double kk) { i = ii; j = jj; kk= kk; } }
-
Which of the following statements are correct about static functions?
- Static functions can access only static data.
- Static functions cannot call instance functions.
- It is necessary to initialize static data.
- Instance functions can call static functions and access static data.
- this reference is passed to static functions.
-
Which of the following statements is correct about constructors?
-
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);
-
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
-
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.
-
How many times can a constructor be called during lifetime of the object?
A.
func() is a valid overloaded function. |
B.
Overloading works only in case of subroutines and not in case of functions. |
C.
func() cannot be considered overloaded because: return value cannot be used to distinguish between two overloaded functions. |
D.
The call to i = s1.func() will assign 1 to i. |
E.
The call j = s1.func() will assign 2.4 to j. |
A.
If we provide a one-argument constructor then the compiler still provides a zero-argument constructor.
|
B.
Static constructors can use optional arguments.
|
C.
Overloaded constructors cannot use optional arguments.
|
D.
If we do not provide a constructor, then the compiler provides a zero-argument constructor.
|