C# class and constructor – programs for practice

(Last Updated On: November 11, 2017)

Q) What is output of C# code?

View Answer
Output:
Base class constructor
Child class constructor
Explanation: In inheritance C# oops relationship, when we create object of a derived or child class then first base class constructor then derived class constructor get called.

Q) What is output of below C# code example?

 

Output:

  1. Compiler error – constructor re-definition
  2. Compiler error – constructor cannot be static
  3. Will print A()
  4. Will print Static A()then A()
View Answer
Answer: D
Explanation: if a class have static constructor then on creation of an object of the class static constructor will be called then class constructor.