C# Programming - Constructors

Exercise : Constructors - General Questions
  • Constructors - General Questions
16.
What will be the output of the C#.NET code snippet given below?
namespace IndiabixConsoleApplication
{ 
    class Sample
    { 
        static Sample()
        { 
            Console.Write("Sample class ");
        }
        public static void Bix1()
        { 
            Console.Write("Bix1 method ");
        } 
    } 
    class MyProgram
    { 
        static void Main(string[ ] args)
        { 
            Sample.Bix1();
        } 
    } 
}
Sample class Bix1 method
Bix1 method
Sample class
Bix1 method Sample class
Sample class Sample class
Answer: Option
Explanation:
No answer description is available. Let's discuss.

17.
Which of the following statements is correct about constructors in C#.NET?
A constructor cannot be declared as private.
A constructor cannot be overloaded.
A constructor can be a static constructor.
A constructor cannot access static data.
this reference is never passed to a constructor.
Answer: Option
Explanation:
No answer description is available. Let's discuss.

18.
What will be the output of the C#.NET code snippet given below?
namespace IndiabixConsoleApplication
{
    class Sample
    { 
        public static void fun1()
        { 
            Console.WriteLine("Bix1 method");
        }
        public void fun2()
        { 
            fun1(); 
            Console.WriteLine("Bix2 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);
        } 
    } 
}
Bix1 method 
123
Bixl method 
Bix2 method
Bix1 method 
123
Bix2 method
Bix2 method 
123
Bix2 method 
Bixl method
Bixl method
123
Bix2 method 
123
Bixl method
Answer: Option
Explanation:
No answer description is available. Let's discuss.