About me

Wednesday, September 30, 2015

Best C# Language Interview Questions and Answers


36. What are abstract classes?



What are the distinct characteristics of an abstract class? An abstract class is a class that cannot be instantiated and is always used as a base class. The following are the characteristics of an abstract class:

• You cannot instantiate an abstract class directly. This implies that you cannot create an object of the abstract class; it must be inherited.
• You can have abstract as well as non-abstract members in an abstract class.
• You must declare at least one abstract method in the abstract class.
• An abstract class is always public.
• An abstract class is declared using the abstract keyword.

The basic objective of an abstract class is to provide a common definition of the base class that multiple derived classes can share

37. Give a brief description of properties in C# and the advantages that are obtained by using them in programs.

In C#, a property is a way to reveal an internal data element of a class in a simple and intuitive manner. In other words, it is a simple extension of data fields. You can create a property by defining an externally available name and then writing the set and get property accessors. The get property accessor is used to return the property value. The set property accessor is used to assign a new value to the property.

38. Explain different types of inheritance.

Inheritance in OOP is of four types:

• Single inheritance - Contains one base class and one derived class
• Hierarchical inheritance - Contains one base class and multiple derived classes of the same base class
• Multilevel inheritance - Contains a class derived from a derived class
• Multiple inheritance - Contains several base classes and a derived class

 All .NET languages supports single, hierarchical, and multilevel inheritance. They do not support multiple inheritance because in these languages, a derived class cannot have more than one base class. However, you can implement multiple inheritance in.NET through interfaces.

39. You have defined a destructor in a class that you have developed by using the C# programming language, but the destructor never executed. Why did the destructor not execute?

 The runtime environment automatically invokes the extirpator of a class to release the resources that are place by variables and methods of an object. However, in C#, programmers cannot control the timing for invoking destructors, as Garbage Collector is only responsible for releasing the resources used by an object. Garbage Collector automatically gets information about unreferenced objects from .NET's runtime environment and then invokes the Finalize() method.

Although, it is not preferable to force Garbage Collector to perform garbage collection and retrieve all inaccessible memory, programmers can use the Collect() method of the Garbage Collector class to forcefully execute Garbage Collector.

40. What is a hashtable?

Hashtable is a data structure that accomplishes the IDictionary interface. It is used to store multiple items and each of these items is associated with a unique string key. Each item can be accessed using the key attached with it. In short, hashtable is an object holding the key-value pairs.


No comments:

Post a Comment