SAP Documents
SAP.

Friday, June 27, 2008

Dot Net Interview Questions - Answers Vol - 4

Q. What is RCW (Runtime Callable Wrappers)?

A. The common language runtime exposes COM objects through a proxy called the runtime callable wrapper (RCW). Although the RCW appears to be an ordinary object to .NET clients, its primary function is to marshal calls between a .NET client and a COM object.

Q. What is CCW (COM Callable Wrapper)

A. A proxy object generated by the common language runtime so that existing COM applications can use managed classes, including .NET Framework classes, transparently.

Q. How will you register com+ services?

A. The .NET Framework SDK provides the .NET Framework Services Installation Tool (Regsvcs.exe - a command-line tool) to manually register an assembly containing serviced components. You can also access these registration features programmatically with the System.EnterpriseServicesRegistrationHelper class by creating an instance of class RegistrationHelper and using the method InstallAssembly

Q. What is use of ContextUtil class?

A. ContextUtil is the preferred class to use for obtaining COM+ context information.

Q. What is Pinvoke?

A. Platform invoke is a service that enables managed code to call unmanaged functions implemented in dynamic-link libraries (DLLs), such as those in the Win32 API. It locates and invokes an exported function and marshals its arguments (integers, strings, arrays, structures, and so on) across the interoperation boundary as needed.

Q. Is it true that COM objects no longer need to be registered on the server?

A. Yes and No. Legacy COM objects still need to be registered on the server before they can be used. COM developed using the new .NET Framework will not need to be registered. Developers will be able to auto-register these objects just by placing them in the 'bin' folder of the application.

Q. What are Sealed Classes in C#?

A. The sealed modifier is used to prevent derivation from a class. A compile-time error occurs if a sealed class is specified as the base class of another class. (A sealed class cannot also be an abstract class)

Q. What are the access-specifiers available in c#?

A. Private, Protected, Public, Internal, Protected Internal.

Q. Explain about Protected and protected internal, “internal” access-specifier?

A. protected - Access is limited to the containing class or types derived from the containing class.

internal - Access is limited to the current assembly.

protected internal - Access is limited to the current assembly or types derived from the containing class.

Q. Difference between type constructor and instance constructor? What is static constructor, when it will be fired? And what is its use?

A. (Class constructor method is also known as type constructor or type initializer)Instance constructor is executed when a new instance of type is created and the class constructor is executed after the type is loaded and before any one of the type members is accessed. (It will get executed only 1st time, when we call any static methods/fields in the same class.) Class constructors are used for static field initialization. Only one class constructor per type is permitted, and it cannot use the vararg (variable argument) calling convention.A static constructor is used to initialize a class. It is called automatically to initialize the class before the first instance is created or any static members are referenced.

Q. What is Private Constructor? and it’s use? Can you create instance of a class which has Private Constructor?

A. When a class declares only private instance constructors, it is not possible for classes outside the program to derive from the class or to directly create instances of it. (Except Nested classes)Make a constructor private if:- You want it to be available only to the class itself. For example, you might have a special constructor used only in the implementation of your class' Clone method.- You do not want instances of your component to be created. For example, you may have a class containing nothing but Shared utility functions, and no instance data. Creating instances of the class would waste memory.

Q. I have 3 overloaded constructors in my class. In order to avoid making instance of the class do I need to make all constructors to private?

A. yes

Q. Overloaded constructor will call default constructor internally?

A. No

Q. Destructor and finalize.

A. Generally in C++ the destructor is called when objects gets destroyed. And one can explicitly call the destructors in C++. And also the objects are destroyed in reverse order that they are created in. So in C++ you have control over the destructors.In C# you can never call them, the reason is one cannot destroy an object. So who has the control over the destructor (in C#)? it's the .Net frameworks Garbage Collector (GC). GC destroys the objects only when necessary. Some situations of necessity are memory is exhausted or user explicitly calls System.GC.Collect() method.Points to remember:

1. Destructors are invoked automatically, and cannot be invoked explicitly.

2. Destructors cannot be overloaded. Thus, a class can have, at most, one destructor.

3. Destructors are not inherited. Thus, a class has no destructors other than the one, which may be declared in it.

4. Destructors cannot be used with structs. They are only used with classes.

5. An instance becomes eligible for destruction when it is no longer possible for any code to use the instance.

6. Execution of the destructor for the instance may occur at any time after the instance becomes eligible for destruction.

7. When an instance is destructed, the destructors in its inheritance chain are called, in order, from most derived to least derived.

Q. What is the difference between Finalize and Dispose (Garbage collection)

A. Class instances often encapsulate control over resources that are not managed by the runtime, such as window handles (HWND), database connections, and so on. Therefore, you should provide both an explicit and an implicit way to free those resources. Provide implicit control by implementing the protected Finalize Method on an object (destructor syntax in C# and the Managed Extensions for C++). The garbage collector calls this method at some point after there are no longer any valid references to the object.In some cases, you might want to provide programmers using an object with the ability to explicitly release these external resources before the garbage collector frees the object. If an external resource is scarce or expensive, better performance can be achieved if the programmer explicitly releases resources when they are no longer being used. To provide explicit control, implement the Dispose method provided by the IDisposable Interface. The consumer of the object should call this method when it is done using the object. Dispose can be called even if other references to the object are alive.Note that even when you provide explicit control by way of Dispose, you should provide implicit cleanup using the Finalize method. Finalize provides a backup to prevent resources from permanently leaking if the programmer fails to call Dispose.

Q. Is goto statement supported in C#? How about Java?

A. Gotos are supported in C#to the fullest. In Java goto is a reserved keyword that provides absolutely no functionality.

1 comment:

Anonymous said...

Do you still use free service like blogspot.com or wordpress.com but
they have less control and less features.
shift to next generation blog service which provide free websites for
your blog at free of cost.
get fully controllable (yourname.com)and more features like
forums,wiki,CMS and email services for your blog and many more free
services.
hundreds reported 300% increase in the blog traffic and revenue
join next generation blogging services at www.hyperwebenable.com
regards
www.hyperwebenable.com