Private Constructor C# | Constructor in C# | #techpointfundamentals

preview_player
Показать описание
Private Constructor C# | Constructor in C# | #techpointfundamentals

Agenda:
Q01. What is Private Constructor in C#?
Q02. What is the default access level of a constructor in C#?
Q03. Is it true that a class having a Private Constructor cannot be inherited?
Q04. Is it true that a class having a Private Constructor cannot be instantiated?
Q05. Can a private constructor be called from the derived class in C#?
Q06. What is the use of a Private Constructor in C#?
Q07. What is nested class in C#?
Q08. Why we should make a singleton class as sealed?
Q09. What is the difference between a class having a private constructor and a Sealed Class?
Q10. What is the difference between a class having a private constructor and a Static Class?
Q11. How can you implement Singleton or Factory in C#?

If a constructor is created with a private access modifier, then it is known as a Private Constructor. A private constructor is a special instance constructor that is generally used in classes that contain static members only.

If we do not use an access modifier with the constructor it will still be private by default. However, the private modifier is usually used explicitly to make it clear that the class cannot be instantiated.

Also a private constructor without having any parameters prevent the automatic generation of the default constructor.

A private constructor is generally used for the singleton implementation.
A class only having a default private constructor cannot be inherited.
Private constructors are used for preventing the instantiation of a class.
A class having only private constructors cannot be instantiated, except the nested class.

Recommended Videos Playlists:
============================================================

Recommended C# Fundamentals Videos:
============================================================

Recommended SQL Videos:
============================================================

Recommended C# Interview Questions Videos:
============================================================

Recommended C# Videos:
============================================================

Follow Us on Social Media Platforms:
============================================================
Рекомендации по теме