C#

C# is an object-oriented programming language developed by Microsoft. C# code gets compiled into MSIL that further executes on CLR.

A delegate holds the reference of a method. We can also pass the delegate/method-reference as a parameter so that another method can execute it when required.

There are two points about Private Constructor.

First, If a class has only private constructor & no public constructor, then it can not be instantiated by any other class except it's nested class. It means private constructor prevents other class to create its instance

Secondly, the private constructor is used in classes that contain only static members.

For example, we use private constructor in the Singleton pattern. Singleton pattern satisfies both of the above conditions.

With the singleton pattern, you get several advantages.

  • First, a singleton can extend classes and implement interfaces, while a static class cannot. See an example here.
  • Singleton class can be passed as a parameter while a static class cannot be.
  • Singleton class can be loaded lazily/asynchronously when needed while static class is always loaded.

No. Static classes can not have instance constructors.

Virtual methods have an implementation & provide derived class an option to override the method.

While Abstract methods don't have the implementation & force the derived class to override the method.

Key points:

  • In Method Overriding, we know what method will be called at run-time. But in Method Hiding, we know what method will be called during compile time.
  • You can think Method Hiding as you are stopping the method from being polymorphic. Hence there won't be any run-time polymorphism.