.NET Interview Questions and Answers

Question.1 What is Object-oriented programming?

Answer: Object-oriented programming (OOP) is a technique to develop logical modules, such as classes, that contain properties, methods, fields, and events. An object is created in the program to represent a class. Therefore, an object encapsulates all the features, such as data and behavior that are associated to a class.

OOP is a technique used by software developers to develop modular programs and assemble them as software. Objects are used to access data and behaviors d different software modules, such as classes, namespaces, and sharable assemblies. .NET Framework supports only object-oriented programming languages. Such as Visual Basic. NET, Visual CS, and Visual C++.

Question.2 What is an object?

Answer: An object is a basic unit of a system and an entity Quires attributes, behaviors, and an identity. Objects are members of a class. Attribute& and behavior of an object are defined by the class definition.

Question.3 What is a class?

Answer: A class is the primary building block of object-oriented programming.

You can use classes as a template, where properties and functionalities or behaviors are put in one building block for a group of objects and use this template to create the objects as needed.

A class contains data and behavior of an entity, for example, the aircraft class can contain data, such as model number, category, and color. The aircraft dam attains behavior, such as duration of night, speed, and number of passengers flown.

In object-oriented programming, a class Merits the data members and behaviors of other classes by expecting from them. Thus, it a is very important for every developer that designing a class must define a type that can be consumed lobar by creating its object.

Question.4 Explain the relationship that exists between an object and a class in the object-oriented programming model.

Answer: Class is a definition. Object is an Instance of the created class. Class is a blue print, while objects are actual objects ‘existing in real world. For example, we have a class called VEHICLE and CAR is the object of that class. We can create any number of objects for the same class.

The new operator is used to create an object of a class. When an object of a class is made, the system allocates the memory for every data member and method that is present in the class.

Question.5 What is an abstract class? What are the distinct characteristics of an abstract class?

Answer: The abstract keyword in a class indicates that the class cannot be instantiated and is an abstract class.

The following are some of the distinct 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. The basic purpose of an abstract class is to provide a common definition of the base class that multiple derived classes can share.

Question.6 State the similarities between a Class and structure?

Answer: structure and Class are the two most important data structures that are used by programmers to build modular programs by using object-oriented programming languages, such as Visual Basic .NET, and Visual C#.

Accesses specifies, such as public, private, and protected, are identically used in structures and classes to restrict the access althea data and methods outside their body.

Both can have constructors, methods, properties, fields, constants, enumerations, events, and event handlers.

Structure and class can implement Interfaces to me multiple inheritance in code.

Both of them can have constructors with parameter.

Both can have delegates and events.

Question.7 Briefly explain the concept of a constructor.

Answer: Constructors are special methods Invoked when instantiating a class or when an object is first created.

The constructor is created with the same name as the class.

You can use a constructor to Initialize member variables and set any parameters.

The main features of constructors are:

Constructors do not have any return type.

Constructors are always public.

It is not mandatory to declare a constructor; it is invoked automatically by.NET Framework.

Question.8 Briefly explain the concept of a destructor.

Answer: A destructor (or finalizer) is called when an object is finally destroyed and the garbage collected.

The constructor is called with the same name as the class, whereas the name of the destructor is made up of the class name prefaced with a tilde (~).

Destructors have no guarantee when they will be called in the application.

C# and Visual Basic provides a garbage collection Mechanism that is executed when the runtime environment finds it necessary or when an object does not destroyed until its reference count drops to 0.

You can, however, implement a custom method that allows you to control object destruction by calling the destructor.

Question.9 What is a static constructor?

Answer: A static constructor initializes static data of a class. CLR calls the static constructor before it calls the first instance constructor. The static constructor is invoked only once, when the program execution begins. Subsequent creation of objects of a class does not invoke a static constructor. Contrary to a static constructor, an instance constructor is created every time the program creates an object of their respective class, that is, instance.

Question.10 Does c# support multiple inheritance?

Answer: C# supports single, hierarchical, and multilevel inheritance because there is only one base class.

It does not support multiple inheritances directly, because in C# a class cannot inherit from more than one class. C# supports multiple inheritances though means of Interlaces.

Question.11 Why is the virtual keyword used in code?

Answer: The Virtual keyword is used in code to define methods and the properties that can be overridden in derived classes.

Question.12 What is shadowing in VB.NET?

Answer: When two elements in a program have the same name, one of them can hide and shadow the ether one. In such cases, the element that shadowed the main element is referenced.

Shadowing is a concept that hips replace the member of a base class with a new member in a delved class, without overriding that member.

You can shadow a base class member in the derived class by using the Shadows keyword. The methods signature, access level, and return type of the shadowed member can be completely different from that of the base class member.

Question.13 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?

Answer: The runtime environment automatically invokes the destructor of a class to release the resources that are occupied 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 perform garbage collection and retrieve all Inaccessible memory, programmers can use the Collect() method of the Garbage Collector class to forcefully execute Garbage Collector.

Question.14 A structure in C# can implement one or more interfaces. is it true or false?

Answer: Yes, It is true. like classes, In C#, structures can Implement one or more Interface.

Question.15 What is a delegate?

Answer: A delegate is a class that can hold a reference to a method or a function. A delegate class has a signature and it can only reference those methods whose signature is compliant with the class. Delegates are type-safe functions pointers or callbacks.

In .NET Framework, a delegate Is a reference to a function.

A delegate is equivalent to a function pointer.

A delegate is declared with the delegate keyword.

Question.16 What is an event?

Answer: An event is an action performed based on another method of the program.

An event Is a delegate-type class member that is used by an object or a class to provide a notification to other objects that an event has occurred. An event can be declared with the help of the event keyword.

Question.17  Can events have access modifiers?

Answer: Yes, you can have access modifiers in events. You can have events with the protected keyword, which will be accessible only to Inherited classes. You can have private events only for objects in that

Question.18 What is a multicast delegate?

Answer: Each delegate object holds reference to a single method. However, it is possible for a delegate object to hold references of and invoke multiple methods. Such delegate objects are called multicast delegates or combinable delegates.

Question.19 Do events have return type?

Answer: No, events do not have return type.

Register For Dot Net Online Training