Constructors Questions
Practice Constructors MCQs with answers and explanations. Page 1 of 1.
Category
C# Programming
Topic
Constructors
Page
1 / 1
Mode
Practice
Questions
Open any question to view the answer and explanation.
C#.NET — Trace static vs instance calls and method overloading to predict console output.
Program:
namespace CuriousTabConsoleApplication
{
class Sample
{
public static void fun1()
{
Console.WriteLine("CuriousTab1 method");
}
public void fun2()
{
fun1();
Console.WriteLine("CuriousTab2 method");
}
public void fun2(int i)
{
Console.WriteLine(i);
fun2();
}
}
class MyProgram
{
static void Main(string[] args)
{
Sample s = new Sample();
Sample.fun1();
s.fun2(123);
}
}
}
What will be printed in order?
Open
View answer
C#.NET — Static constructor vs static method: determine the order of outputs.
Program:
namespace CuriousTabConsoleApplication
{
class Sample
{
static Sample()
{
Console.Write("Sample class ");
}
public static void CuriousTab1()
{
Console.Write("CuriousTab1 method ");
}
}
class MyProgram
{
static void Main(string[] args)
{
Sample.CuriousTab1();
}
}
}
What will be printed?
Open
View answer
C#.NET — Can you prevent outside code from creating an instance by using (or controlling) the parameterless constructor?
Give the precise rule used in C# object-oriented design.
Open
View answer
C#.NET constructors — Choose the correct definitions so that both of the following lines compile and create objects:
Sample s1 = new Sample();
Sample s2 = new Sample(9, 5.6f);
Open
View answer
C#.NET — For the class below, which object-creation statements will compile?
class Sample
{
int i;
Single j;
double k;
public Sample(int ii, Single jj, double kk)
{
i = ii;
j = jj;
k = kk;
}
}
Open
View answer
C#.NET — Which statement about constructors is correct?
Open
View answer
C#.NET — Is it possible to explicitly invoke the Garbage Collector (GC)?
Open
View answer
C#.NET — For methods to be considered overloaded, which aspects must differ? (Select the correct set.)
Consider: Type of arguments; Return type of methods; Number of arguments; Names of methods; Order of arguments.
Open
View answer
C#.NET — Which statements about static methods are correct?
Open
View answer
C#.NET — Analyze static vs instance access in the following code and select the correct statement(s):
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;
}
}
Open
View answer
C#.NET — Which statement is correct regarding constructors and destructors?
Open
View answer
C#.NET overloading — What is wrong with the following code and which statement is correct?
namespace CuriousTabConsoleApplication
{
class Sample
{
public int func()
{
return 1;
}
public Single func()
{
return 2.4f;
}
}
class Program
{
static void Main(string[] args)
{
Sample s1 = new Sample();
int i;
i = s1.func();
Single j;
j = s1.func();
}
}
}
Open
View answer
C#.NET — Which statement about constructors is correct?
Open
View answer
C#.NET — Can a static method access instance data directly?
Open
View answer
C#.NET — During the lifetime of a single object, how many times can its constructor run?
Open
View answer
C#.NET — Identify the correct statements about constructors:
Open
View answer
C#.NET — Which statement about the garbage collector (GC) is correct?
Open
View answer
C#.NET — Which statements about static methods are correct?
Open
View answer
Practice smarter
Solve a few questions daily and revisit weak topics regularly to improve accuracy.