.NET - Object-Oriented Programming
45.
Explain the concept of destructor?
A destructor is a special method for a class and is invoked automatically when an object is finally destroyed. The name of the destructor is also same as that of the class but is followed by a prefix tilde (~).
A destructor is used to free the dynamic allocated memory and release the resources. You can, however, implement a custom method that allows you to control object destruction by calling the destructor.
The main features of a destructor are as follows:
A destructor is used to free the dynamic allocated memory and release the resources. You can, however, implement a custom method that allows you to control object destruction by calling the destructor.
The main features of a destructor are as follows:
- Destructors do not have any return type
- Similar to constructors, destructors are also always public
- Destructors cannot be overloaded.
46.
Can you declare a private class in a namespace?
The classes in a namespace are internal, by default. However, you can explicitly declare them as public only and not as private, protected, or protected internal. The nested classes can be declared as private, protected, or protected internal.
47.
A structure in C# can implement one or more interfaces. Is it true or false?
Yes, it is true. Like classes, in C#, structures can implement one or more interfaces.
48.
What is a static constructor?
Static constructors are introduced with C# to initialize the static data of a class. CLR calls the static constructor before the first instance is created.
The static constructor has the following features:
The static constructor has the following features:
- No access specifier is required to define it.
- You cannot pass parameters in static constructor.
- A class can have only one static constructor.
- It can access only static members of the class.
- It is invoked only once, when the program execution begins.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers