Search This Blog

Thursday 24 July 2014

All Dotnet Interview Questions 50-100

Question 51 - What is a Resource File?
Resource files are the files containing data that is logically deployed with an application. These files can contain data in a number of formats including strings, images and persisted objects. It has the main advantage of If we store data in these files then we don't need to compile these if the data get changed. In .NET we basically require them storing culture specific information’s by localizing application's resources. You can deploy your resources using satellite assemblies.

Question 52 - What is Code Access Security(CAS)?
CLR allows code to perform only those operations that the code has permission to perform. So CAS is the CLR's security system that enforces security policies by preventing unauthorized access to protected resources and operations. Using the Code Access Security, you can do the following:
·         Restrict what your code can do
·         Restrict which code can call your code
·         Identify code
Code access security consists of the following elements:
·         Permissions - represent access to a protected resource or the ability to perform a protected operation.
·         Permission sets - A permission set is a collection of permissions.
·         Code groups - logical grouping of code that has a specified condition for membership Evidence
·         Policy - Security policy is the configurable set of rules that the CLR follows when determining the permissions to grant to code.
·         There are four policy levels - Enterprise, Machine, User and Application Domain, each operating independently from each other.
Syntax
·         See CAS objects -- Run 'caspol -lg' from command line.
·         Add CAS objects -- caspol -ag 1.3 -site www.mydomain.com FullTrust
·         Change CAS obj -- caspol -cg 1.3 FullTrust
·         Turn Off -- caspol -s off

Question 53 - What is difference between Code Based Security and Role Based Security?
CAS is the approach of using permissions and permission sets for a given code to run. Example, Admin can disable running executables off the Internet or restrict access to corporate database to only few applications.
·         Role security most of the time involves the code running with the privileges of the current user. This way the code cannot supposedly do more harm than mess up a single user account.
·         Neither is better. It depends on the nature of the application; both code-based and role-based security could be implemented to an extent.

Question 54 - What is difference between Invoke and Begin Invoke
·         Delegate.Invoke: Executes synchronously, on the same thread.
·         Delegate.BeginInvoke: Executes asynchronously, on a threadpool thread.
·         Control.Invoke: Executes on the UI thread, but calling thread waits for completion before continuing.
·         Control.BeginInvoke: Executes on the UI thread, and calling thread doesn't wait for completion.
·         BeginInvoke is asynchronous. When BeginInvoke is called from the UI thread the request will be executed in parallel with the UI thread. Which means it may not execute until after the currently executing method has returned. So in this case the text box will never appear to update because the for loop will not be interrupted, as the calling thread will not wait for this event to be completed before continuing.
·         Alternatively, Invoke is synchronous. The text box will be updated because the calling thread will wait for the call to complete before continuing execution.

Question 55 - What is the difference between Debug and Trace?
Tracing is actually the process of collecting information about the program's execution. Debugging is the process of finding & fixing errors in our program. Tracing is the ability of an application to generate information about its own execution.
Trace and Debug work in a similar way, the difference is that tracing from the Debug class only works in builds that have the DEBUG symbol defined, whereas tracing from the Trace class only works in builds that have the TRACE symbol defined.
·         Use System.Diagnostics.Trace.WriteLine for tracing that you want to work in debug and release builds
·         Use System.Diagnostics.Debug.WriteLine for tracing that you want to work only in debug builds.
 Question 56 - What is a Debug version of a code?
·         Preprocessor(Debugging Diagnostic) macro _DEBUG is enabled.
·         More memory size.
·         Support files required. (MFC Dll’s)
·         No Code Optimization
·         Uses MFC Debug Library
·         ASSERT is enabled.
·         Execution takes more time
 
Question 57 - What is a Release version of a code?
·         Preprocessor(Debugging Diagnostic) macro NDEBUG is enabled.
·         Less memory size.
·         Support files not required. (MFC Dll’s)
·         Code Optimization
·         Uses MFC Release Library
·         ASSERT is disabled anything inside of ASSERT will not be executed.
·         Execution takes less time

Question 58 - What is an IDisposable Interface?
·         The primary use of this interface is to release unmanaged resources. The garbage collector automatically releases the memory allocated to a managed object when that object is no longer used.
·         However, it is not possible to predict when garbage collection will occur.
·         Furthermore, the garbage collector has no knowledge of unmanaged resources such as window handles, or open files and streams.
·         The consumer of an object can call this method when the object is no longer needed.

Question 59 - What is Finalize block in .net?
·         Finalize() is called by the runtime
·         Is a C# equivalent of destructor, called by Garbage Collector when the object goes out of scope.
·         Implement it when you have unmanaged resources in your code, and want to make sure that these resources are freed when the Garbage collection happens.
·         Finalize() can NOT be overridden or called in C#.
·         Since, Finalize() is called by the Garbage Collector, it is non-deterministic.

Question 60 - What is Dispose block in .net?
·         Dispose() is called by the user
·         Same purpose as finalize, to free unmanaged resources. However, implement this when you are writing a custom class, that will be used by other users.
·         Overriding Dispose() provides a way for user code to free the unmanaged objects in your custom class.
·         Dispose() has to be implemented in classes implementing IDispose interface.
·         Dispose() method is called explicitly in the code itself.
Question 61 - What is Runtime Host?
Ranging from Windows applications, Web applications to Mobile applications, CLR is designed to support various types of applications. .NET Framework provides different types of runtime hosts to manage the execution of application code(to load runtime in to process, create application domain within process, load user code in to application domain) and provides various services to the application. Runtime hosts included in .Net framework are : ASP.NET, Microsoft Internet Explorer and windows shell.

Question 62 - What is Connection Pooling?
·         A Connection Pool is a container of open and reusable connections. A Connection Pool is released from the memory when the last connection to the database is closed.
·         The Data Providers in ADO.NET have Connection Pooling turned on by default; if you need to turn it off, specify Pooling = false in the connection string being used.
·         Connection Pooling gives you an idle, open, reusable connection instead of opening a new one every time a connection request to the database is made. When the connection is closed or disposed, it is returned to the pool and remains idle until a request for a new connection comes in.
·         The pool can house connections up to the maximum limit as specified in the connection string that was used to connect to the database.
·         Advantage of using Connection Pooling is an improvement of performance and scalability
·         Disadvantage is that one or more database connections, even if they are currently not used, are kept open.

Question 63 - What are the main parameters used by Connection Pooling?
Connection Pooling is controlled and the parameters passed to a connection string comprises the following:
·         Connect Timeout
·         Min Pool Size
·         Max Pool Size
·         Pooling

Question 64 - What is Connection Pool Manager?
A Connection Pool is maintained internally by the Connection Pool Manager. When a request for a subsequent connection comes in, the Connection Pool Manager searches the pool for the availability of a free connection and returns it to the application if one is available. Connection Pools works as below
·         If any unused connection is available, it returns one.
·         If all connections are used up, a new connection is created and added to the pool.
·         If the number of connections reaches the maximum number of connections in the pool, the requests are queued until a connection becomes free for reuse.

Question 65 - What is Object Pooling?
It is something that tries to keep a pool of objects in memory to be re-used later and hence it will reduce the load of object creation to a great extent. Whenever there is a request for a new object, the pool manager will take the request and it will be served by allocating an object from the pool. Pooling basically means utilizing the resources efficiently, by limiting access of the objects to only the period the client requires it.

Question 66 - What are the Advantages of Object Pooling?
It minimizes the consumption of memory and the system's resources by recycling and re-using objects as and when it is needed and serving the request for new objects from the pool of ready-to-be-used objects. The objects that the application is done with (the objects are no longer needed) are sent back to the pool rather than destroying them from the memory.
According to MSDN, "Once an application is up and running, memory utilization is affected by the number and size of objects the system requires. Object pooling reduces the number of allocations, and therefore the number of garbage collections, required by an application.

Question 67 - What is the Difference between Connection Pooling and Object Pooling?
Object Pooling is great in the sense that it can optimize access to expensive resources (like file handles or network connections) by pooling them in memory and reusing them as and when they are needed.
According to MSDN, "Object pooling lets you control the number of connections you use, as opposed to connection pooling, where you control the maximum number reached."

Question 68 - What is an Indexer?
·         Indexers permit instances of a class or struct to be indexed in the same way as arrays.
·         Indexers are similar to properties except that their accessors take parameters.
·         The indexers are usually known as smart arrays in C#.
·         An indexer, also called an indexed property, is a class property that allows you to access a member variable of a class using the features of an array.
·         Defining an indexer allows you to create classes that act like virtual arrays. Instances of that class can be accessed using the [] array access operator.

Question 69 - What are the important points to remember on indexers?
·         Indexers are always created with this keyword.
·         Parameterized property are called indexer.
·         Indexers are implemented through get and set accessors for the [ ] operator.
·         ref and out parameter modifiers are not permitted in indexer.
·         Indexer is an instance member so can't be static but property can be static.
·         Indexers are used on group of elements.
·         Indexer can be overloaded.

Question 70 - What is the Difference between Indexers and Properties?
Indexers
Properties
Indexers are created with this keyword
Properties don't require this keyword
Indexers are identified by signature
Properties are identified by their names
Indexers are accessed using indexes
Properties are accessed by their names
Indexer are instance member, so can't be static
Properties can be static as well as instance members

Question 71 - What are the different Access Modifiers available?
·         Public - Access to same assembly or another assembly that references it.
·         Private - Access to same class or struct.
·         Protected - Access to same class or struct, or in a class that is derived.
·         Internal - Access to any code in the same assembly, but not from another assembly.
·         Protected Internal - Access to any code in the assembly in which it is declared, or from within a derived class in another assembly.
Question 72 - What are the differences between Class and Struts?
Class
Struct
Class is a reference type
Struct is a value type
Class supports inheritance
Struct will not support inheritance
Class variables are stored on Heap
Struct variables are stored on Stack
Class can have destructor
Struct will not have destructor
Boxing a class object creates reference to same object
Boxing a strut object will create a copy in diff type
All the members of Class are private by default
All the members of struct are public by default
Class is well suited for Data hiding
Struts are not suited for Data hiding

Question 73 - What are the Similarities between Class and Struts?
Both are user defined types.
Both of them can have constructor without parameter and with parameter.Both can have delegates and events.Both can have methods, properties , fields, constants , enumerations, events.

Question 74 - What is the term Virtual means?
When we need to override a method of the base class in the sub class, then we give the virtual keyword in the base class method. This makes the method in the base class to be overridable. Methods, properties, and indexers can be virtual, which means that their implementation can be overridden in derived classes. You cannot use the virtual modifier with the following modifiers:
·         Static,
·         Abstract
·         Override
Question 75 - What is a Sealed Class?
·         Sealed classes are used to restrict the inheritance feature of object oriented programming.
·         Once class is defined as sealed class, this class cannot be inherited so we can’t derive class.
·         Keywords: C# - Sealed , VB.NET - NotInheritable
·         If you have ever noticed, struct are sealed. You cannot derive a class from a struct.
·         A sealed class cannot be used as a base class. For this reason, it cannot also be an abstract class.
·         The best usage of sealed classes is when you have a class with static members.
·         Example - The Pens and Brushes classes of the System.Drawing namespace. The Pens class represent the pens for standard colors.
·         This class has only static members. Pens.Blue represents a pen with blue color. Similarly, the Brushes class represents standard brushes.
·         The Brushes.Blue represents a brush with blue color.
Question 76 - What is Polymorphism?
·         Polymorphism is one of the primary characteristics (concept) of object-oriented programming.
·         Poly means many and morph means form. Thus, polymorphism refers to being able to use many forms of a type without regard to the details.
·         Polymorphism is the characteristic of being able to assign a different meaning specifically, to allow an entity such as a variable, a function, or an object to have more than one form.
·         Polymorphism is the ability to process objects differently depending on their data types.
·         Polymorphism is the ability to redefine methods for derived classes.

Question 77 - What are the Types of Polymorphism?
·         Compile time Polymorphism (method overloading)
·         Run time Polymorphism (method overriding)

Question 78 - What is Method Overloading? Or What is Early Binding?
Method overloading means having two or more methods with the same name but with different signatures

Question 79 - What is Method Overriding or What is Late Binding?
Method overriding means having two or more methods with the same name , same signature but with different implementation. (Base class and Child class implementation of a method with same name and signature)

Question 80 - What is an Inheritance?
It is the ability to use all of the functionality of an existing class, and extend those capabilities without re-writing the original class. It is the process by which one object acquires the properties of another object. A new class that is created by inheritance is sometimes called a child class or a subclass. The class you originally inherited from is called the base class, parent class, or the superclass.
Question 81 - What are the Types of Inheritance?
·         Implementation inheritance refers to the ability to use a base class's properties and methods with no additional coding.
·         Interface inheritance refers to the ability to use just the names of the properties and methods, but the child class must provide the implementation.
·         Visual inheritance refers to the ability for a child form (class) to use the base forms (class) visual representation as well as the implemented code.

Question 82 - What is Multiple Inheritance?
C# does not support multiple implementation inheritance. A class cannot be derived from more than one class, However, a class can be derived from multiple interfaces.

Question 83 - What are the examples of Multiple Inheritance?
Imagine a class named TransmitData, whose function is to transmit data, and another class named ReceiveData, whose function is to receive data. Now imagine that you want to create a class named SocketPort, whose function is to transmit and receive data. In order to accomplish this, you would want to derive SocketPort from both TransmitData and ReceiveData.

Question 84 - What are the Advantages of Inheritance?
·         Once a behavior (method) or property is defined in a super class(base class),that behavior or property is automatically inherited by all subclasses (derived class).
·         Code reusability increased through inheritance.
·         Inheritance provide a clear model structure which is easy to understand without much complexity Using inheritance, classes become grouped together in a hierarchical tree structure Code are easy to manage and divided into parent and child classes.

Question 85 - What is an Encapsulation?
·         Encapsulation is a process of hiding all the internal details of an object from the outside world.
·         Encapsulation is the ability to hide its data and methods from outside the world and only expose data and methods that are required
·         Encapsulation gives us maintainability, flexibility and extensibility to our code.
·         Encapsulation makes implementation inaccessible to other parts of the program and protect from whatever actions might be taken outside the function or class.
·         Encapsulation provides a way to protect data from accidental corruption
·         Encapsulation hides information within an object
·         Encapsulation is technique or process of making fields in a class private and providing access to the fields using public methods
·         Encapsulation allows us to create a "black box" and protects an objects internal state from corruption by its clients.
·         The idea of encapsulation comes from the need to cleanly distinguish between the specification and the implementation of an operation and the need for modularity.

Question 86 - What are the examples of Encapsulation?
·         Let's say you have an object named Bike and this object has a method named start(). When you create an instance of a Bike object and call its start() method you are not worried about what happens to accomplish this, you just want to make sure the state of the bike is changed to 'running' afterwards. This kind of behavior hiding is encapsulation and it makes programming much easier.
·         Video Recorder, which has a record, play, pause buttons is another example of encapsulation, so VCR is encapsulated into a single object where the internals can change but stays the same for users interface point of view.
·         Medical Capsules i.e. one drug is stored in bottom layer and another drug is stored in Upper layer these two layers are combined in single capsule.

Question 87 - What is an Abstraction?
·         Abstraction means to show only the necessary details to the client of the object.
·         Abstraction is about paying attention to the details that are relevant and ignoring the rest.
·         It refers to act of representing essential features without including background details / explanations.

Question 88 - What are the examples of Abstraction?
·         Do you know the inner details of the Monitor of your PC? What happen when you switch ON Monitor? No Right, Important thing for you is weather Monitor is ON or NOT.
·         When you change the gear of your vehicle are you really concern about the inner details of your vehicle engine? No but what matter to you is that Gear must get changed that’s it!!
·         Let’s say you have a method "CalculateSalary" in your Employee class, which takes EmployeeId as parameter and returns the salary of the employee for the current month as an integer value. Now if someone wants to use that method. He does not need to care about how Employee object calculates the salary? An only thing he needs to be concern is name of the method, its input parameters and format of resulting member. This is abstraction; show only the details which matter to the user.
·         TV Remote Button in that number format and power buttons and other buttons there just we are seeing the buttons, we don't see the button circuits .i.e buttons circuits and wirings all are hidden.

Question 89 - Difference between Encapsulation and Abstraction ?
Encapsulation
Abstraction
Hiding the internal details or mechanics of how an object does something.
It focus on what the object does instead of how it does it.
Binding data and member functions together inside a single unit.
Hiding the complexities of your type from outside world.
Eg: VCR Example
Eg: Monitor Example

Question 90 - What is an Abstract Class?
·         It is a class that cannot be instantiated, it exists extensively for inheritance and it must be inherited.
·         Abstract classes cannot be used to instantiate objects; because abstract classes are incomplete
·         Abstract classes may contain only definition of the properties or methods.
·         Derived classes that inherit the abstract class needs to implements it's properties or methods.
·         An abstract class is essentially a blueprint for a class without any implementation.
·         An abstract class is a class that must be inherited and have the methods overridden.
§  An abstract class cannot be a sealed class.
§  An abstract method cannot be private.
§  An abstract member cannot be static.
·         An abstract method cannot have the modifier virtual. Because an abstract method is implicitly virtual.
·         The access modifier of the abstract method should be same in both the abstract class and its derived class. If you declare an abstract method as protected, it should be protected in its derived class. Otherwise, the compiler will raise an error.
Question 91 - What is an Interface?
·         An interface looks like a class, but has no implementation.
·         An interface is a named set of method signatures.
·         An Interface is a reference type and it contains only abstract members.
·         An interface is an array of related function that must be implemented in derived type.
·         Members of an interface are implicitly public & abstract.
·         It can contain definitions of events, indexers, methods parameter less and parameterful properties.
·         The interface can't contain constants, data fields, constructors, destructors and static members.
·         All the member declarations inside interface are implicitly public. 
·         Interfaces are great for putting together plug-n-play like architectures where components can be interchanged at will. Since all interchangeable components implement the same interface, they can be used without any extra programming.

Question 92 - What is a difference between Abstract Class and Interface?
Abstract Class
Interface
Cannot be instantiated, means one cannot make a object of this class.
We can only define method definition and no implementation.
Access modifiers are allowed
Access modifiers are not allowed
Some methods can be concrete
All methods are abstract
A class can inherit only one abstract class
A class can inherit many interfaces.
Can have any access modifiers
By default its public static final
Can have constructor and destructor
Cannot have constructor and destructor
Only one abstract class can be derived
Class can have multiple interfaces
Requires more time to find actual method in class
Faster
Abstract class provides 0 to 100% generalization
Interface provides 100% generalization
It provides both generalization and specialization
Interface provides only Generalization

Question 93 - What is a Constructor?
·         Constructor is used to initialize an object (instance) of a class.
·         Constructor is a like a method without any return type.
·         Constructor has same name as class name.
·         Constructor follows the access scope (Can be private, protected, public, Internal and external).
·         Constructor can be overloaded, means we can have constructors with different set of parameters.
·         We can always make the call to one constructor from within the other constructor. 
·         Only this and base keywords allowed in initializing constructors, other method calls will raise error.

Question 94 - What is a Constructor chaining?
Overloading the constructor using the this and base keywords so that it overload is called constructor chaining

Question 95 - What are the Types of constructors?
·         Static Constructor
·         Default Constructor
·         Private Constructor
·         Copy Constructor 
·         Parameterized Constructor
Question 96 - What is a Private Constructor?
·         Used to prevent the user to instantiate the class directly.
·         Used to prevent the creation of instances of a class when there are no instance fields or methods
·         A private constructor is a special instance constructor.
·         It is commonly used in classes that contain static members only.
·         If a class has one or more private constructors and no public constructors, then other classes (except nested classes) are not allowed to create instances of this class.
·         Note that if you don't use an access modifier with the constructor it will still be private by default.
·         Private constructors are used to restrict the instantiation of object using 'new' operator.
·         This type of constructors is mainly used for creating singleton object.
·         Can use nested class (Inner Class) or static method to initialize a class having private constructor. 
·         Example of Private Constructor - Math class

Question 97 - What is a Static Constructors?
·         Special constructor and gets called before the first object is created of the class.
·         The time of execution cannot be determined, but it is definitely before the first object creation - could be at the time of loading the assembly.
·         Static constructors might be convenient, but they are slow. The runtime is not smart enough to optimize them in the same way it can optimize inline assignments.
·         The static constructor for a class executes before any of the static members for the class are referenced.
·         The static constructor for a class executes after the static field initializers (if any) for the class.
·         A static constructor cannot be called directly.
·         The user has no control on when the static constructor is executed in the program. 
·         Example - When the class is using a log file and the constructor is used to write entries to this file.

Question 98 - What are the features of Static Constructor?
·         Only one Static constructor - Overloading needs the two methods to be different in terms to methods definition, so you can have at the most one static constructor 
·         Without parameters - It is going to be called by CLR, who can pass the parameters to it, if required, No one, so we cannot have parameterized static constructor. 
·         Access only static members - If allowed to work on non-static members, will reflect the changes in all the object instances, which is impractical. Non-static members in the class are specific to the object instance 
·         No access modifier - The call to the static method is made by the CLR and not by the object, so we do not need to have the access modifier to it.

Question 99 - What is a Default Constructor?
·         A default constructor is a constructor in both that has no parameters or where it has parameters they are all defaulted.
·         If no constructor is supplied then the compiler will supply a default constructor. 
·         This default constructor is a parameter less constructor with no body, which calls the parameter less constructor of the base class.

Question 100 - What is a COPY Constructor?
·         C# does not provide a copy constructor.
·         A copy constructor is a special constructor used to create a new object as a copy of an existing object.
·         This constructor takes a single argument: a reference to the object to be copied.
·         It is a great convenience to create copy constructor for C# classes using Reflection.
·         If you create a new object and want to copy the values from an existing object, you have to write the appropriate method yourself.
Question 101 - What is a Parameterized constructor?

Constructor that accepts arguments is known as parameterized constructor. There may be situations, where it is necessary to initialize various data members of different objects with different values when they are created. Parameterized constructors help in doing that task.

No comments:

Post a Comment