Questions asked to me in my interviews!

1. What is a sealed class?

A class which cannot be inherited is called sealed class. Any class can be marked as sealed using sealed keyword.

2. Difference between Interface and Abstract class?

Abstract class and Interface are defined as below:

Abstract Class: It is a special type of class which cannot be instantiated. That is we cannot create objects for this class because we have not defined it completely. They should have at least one empty method declared as abstract. They have to be inherited by some other class to define completely.

Interface: It is a special entity defined using a keyword Interface. It does not have any implementation, i.e. it has empty methods (no definitions). They have to be inherited by another class.

Mentioned below are few differences between them:
1. A class can inherit multiple Interfaces, but only a single abstract class.
2. An abstract class can have one or more completed methods, whereas Interface must have no methods with definitions.
3. Interfaces have to be public where as abstract classes can have any of the access specifiers.
4. Interfaces cannot be changed once they are created. Abstract classes can be modified.

3. What is the difference between overloading and overriding?

Overloading: Declaring two or more methods with same name but different signatures or parameters is called overloading.

Overriding: Rewriting a method of base class in one of its sub classes is called overriding. This is done by inheritance using virtual and override keywords.

4. What is a stored procedure?

A Stored procedure is a set of Transact-SQL Statements used together as a unit. This unit is compiled only once and can be executed as many times as possible without any need for further compilation.

5. Difference between stored procedure and function?

1. Must return a value.
2. Do not have output parameters
3. They can be called from a procedure.
4. Can have only select statements.
5. No exception handing
Stored Procedures:
1. Returning a value is optional.
2. Can have input/output/no parameters
3. Stored procedures cannot be called by functions.
4. Can have Select or any DML (Insert/Update/Delete) statements.
5. Try-catch blocks are possible.

6. Can an SQL function return a table?

Yes. They can return a table.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s