Wednesday 13 February 2008

Brushing up on interview questions

What is the difference between clustered and nonclustered indexes?

There are clustered and nonclustered indexes. A clustered index is a special type of index that reorders the way records in the table are physically stored. Therefore table can have only one clustered index. The leaf nodes of a clustered index contain the data pages.

A nonclustered index is a special type of index in which the logical order of the index does not match the physical stored order of the rows on disk. The leaf node of a nonclustered index does not consist of the data pages. Instead, the leaf nodes contain index rows.

Abstract and Sealed keywords
The abstract keyword enables you to create classes and class members solely for the purpose of inheritance. The classes, which we can't initialize, are known as abstract classes. They provide only partial implementations. But another class can inherit from an abstract class and can create their instances.

The sealed keyword enables you to prevent the inheritance of a class or certain class members that were previously marked virtual.

Virtual keyword
The virtual keyword is used to modify a method, property, indexer, or event declaration and allow for it to be overridden in a derived class

Structs vs Classes
Structs are value types, unlike classes they do not require heap allocation. Also, as value types they cannot be derived from. Structs can implement an interface.

Early vs Late Binding
Early binding is when your client app can detect at compile time what object a property or method belongs to. Since it "knows", it resolves the references and the compiled executable contains only the code to invoke the object's properties, methods, events, etc.

This is a good thing if you want to speed because the call overhead is greatly reduced.

Late binding is the slowest way to invoke the properties and methods of an object. You use late binding when you write a function that uses an object variable that acts on any of several different class objects. Since the compiler doesn't "know" what class object will be assigned to the variable, it doesn't resolve the references into the compiled executable. In this case they are resolved at runtime... when you actually have an assigned object to reference the properties and methods to.

No comments: