Get Paid By Click

Mginger Mobile Money

Jul 27, 2010

OOPS Interview Questions and Answers

OBJECT ORIENTED PROGRAMMING(Based on C#)

1) What is meant by Object Oriented Programming?
     OOP is a method of programming in which programs are organised as cooperative collections of objects. Each object is an instance of a class and each class belong to a hierarchy.

2) What is a Class?
     Class is a template for a set of objects that share a common structure and a common behaviour.

3) What is an Object?
     Object is an instance of a class. It has state,behaviour and identity. It is also called as an instance of a class.

4) What is an Instance?
     An instance has state, behaviour and identity. The structure and behaviour of similar classes are defined in their common class. An instance is also called as an object.

5) What are the core OOP’s concepts?
     Abstraction, Encapsulation,Inheritance and Polymorphism are the core OOP’s concepts.

6) What is meant by abstraction?
     Abstraction defines the essential characteristics of an object that distinguish it from all other kinds of objects. Abstraction provides crisply-defined conceptual boundaries relative to the perspective of the viewer. Its the process of focussing on the essential characteristics of an object. Abstraction is one of the fundamental elements of the object model.

7) What is meant by Encapsulation?
     Encapsulation is the process of compartmentalising the elements of an abtraction that defines the structure and behaviour. Encapsulation helps to separate the contractual interface of an abstraction and implementation.

8) What is meant by Inheritance?
     Inheritance is a relationship among classes, wherein one class shares the structure or behaviour defined in another class. This is called Single Inheritance. If a class shares the structure or behaviour from multiple classes, then it is called Multiple Inheritance. Inheritance defines “is-a” hierarchy among classes in which one subclass inherits from one or more generalised superclasses.

9) What is meant by Polymorphism?
     Polymorphism literally means taking more than one form. Polymorphism is a characteristic of being able to assign a different behavior or value in a subclass, to something that was declared in a parent class.

10) What is an Abstract Class?
     Abstract class is a class that has no instances. An abstract class is written with the expectation that its concrete subclasses will add to its structure and behaviour, typically by implementing its abstract operations.

11) What is an Interface?
     Interface is an outside view of a class or object which emphaizes its abstraction while hiding its structure and secrets of its behaviour.

12) What is a base class?
     Base class is the most generalised class in a class structure. Most applications have such root classes. In Java, Object is the base class for all classes.

13) What is a subclass?
     Subclass is a class that inherits from one or more classes

14) What is a superclass?
     superclass is a class from which another class inherits.

15) What is a constructor?
     Constructor is an operation that creates an object and/or initialises its state.

16) What is a destructor?
     Destructor is an operation that frees the state of an object and/or destroys the object itself. In Java, there is no concept of destructors. Its taken care by the JVM.

17) What is meant by Binding?
     Binding denotes association of a name with a class.

18) What is meant by static binding?
     Static binding is a binding in which the class association is made during compile time. This is also called as Early binding.

19) What is meant by Dynamic binding?
     Dynamic binding is a binding in which the class association is not made until the object is created at execution time. It is also called as Late binding.

20) Define Modularity?
     Modularity is the property of a system that has been decomposed into a set of cohesive and loosely coupled modules.

21) What is meant by Persistence?
     Persistence is the property of an object by which its existence transcends space and time.

22) What is colloboration?
     Colloboration is a process whereby several objects cooperate to provide some higher level behaviour.

23) In Java, How to make an object completely encapsulated?
     All the instance variables should be declared as private and public getter and setter methods should be provided for accessing the instance variables.

24) How is polymorphism acheived in java?
     Inheritance, Overloading and Overriding are used to acheive Polymorphism in java.


 Use the new modifier to explicitly hide a member inherited from a base class. To hide an inherited member, declare it in the derived class using the same name, and modify it with the new modifier.

 Yep. But ..

* Its possible If its a static method.

* Its possible by inheriting from that class also.

* Its possible from derived classes using base keyword.

 Use the override modifier to modify a method, a property, an indexer, or an event. An override method provides a new implementation of a member inherited from a base class. The method overridden by an override declaration is known as the overridden base method. The overridden base method must have the same signature as the override method.

You cannot override a non-virtual or static method. The overridden base method must be virtual, abstract, or override.

 Method overloading occurs when a class contains two methods with the same name, but different signatures.


Method overriding is a feature that allows to invoke functions (that have the same signatures) and that belong to different classes in the same hierarchy of inheritance using the base class reference. In C# it is done using keywords virtual and overrides .

For more information visit http://www.codeproject.com/KB/cs/cs_methodoverride.aspx


Method overloading allows us to write different version of the same method in a class or derived class. Compiler automatically select the most appropriate method based on the parameter supplied.
public class MultiplyNumbers
{
    public int Multiply(int a, int b)
    {
        return a * b;
    }
  
    public int Multiply(int a, int b, int c)
    {
        return a*b*c;
    }     
}


To call the above method, you can use following code.
MultiplyNumbers mn = new MultiplyNumbers();
int number = mn.Multiply(2, 3) // result = 6
int number1 = mn.Multiply(2, 3, 4) // result = 24
 


You can't have a overload method with same number parameters but different return type. In order to create overload method, the return type must be the same and parameter type must be different or different in numbers.

 An enum has default modifier as public

A class has default modifiers as private . It can declare members (methods etc) with following access modifiers:
public
protected
internal
private
protected internal

An interface has default modifier as public

A struct has default modifier as private and it can declare its members (methods etc) with following access modifiers:
public
internal
private


Protected Internal is a access modifiers for the members (methods or functions) ie. you can't declare a class as protected internal explicitly. The members access is limited to the current assembly or types derived from the containing class.

Protected Internal means the method is accessible by anything that can access the protected method
UNION with anything that can access the internal method.

For more details read http://haacked.com/archive/2007/10/29/what-does-protected-internal-mean.aspx

 The internal keyword is an access modifier for types and type members ie. we can declare a class as internal or its member as internal. Internal members are accessible only within files in the same assembly (.dll). In other words, access is limited exclusively to classes defined within the current project assembly.

For more details see http://msdn.microsoft.com/en-us/library/7c5ka91b(VS.71).aspx

 The private keyword is a member access modifier ie. we can't explicitly declare a class as Private, however if do not specify any access modifier to the class, its scope will be assumed as Private. Private access is the least permissive access level of all access modifiers.

Private members are accessible only within the body of the class or the struct in which they are declared. This is the default access modifier for the class declaration.

For more details, see http://msdn.microsoft.com/en-us/library/st6sy9xe(VS.71).aspx

 The public keyword is an access modifier for types and type members ie. we can declare a class or its member (functions or methods) as Public. There are no restrictions on accessing public members.


The protected keyword is a member access modifier. It can only be used in a declaring a function or method not in the class ie. a class can't be declared as protected class.

A protected member is accessible from within the class in which it is declared, and from within any class derived from the class that declare this member. In other words access is limited to within the class definition and any class that inherits from the class

A protected member of a base class is accessible in a derived class only if the access takes place through the derived class type.

For more details see http://msdn.microsoft.com/en-us/library/bcd5672a(VS.71).aspx


 Private, Protected, Public, Internal, Protected Internal.


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)

 Operator overloading is a concept that enables us to redefine (do a special job) the existing operators so that they can be used on user defined types like classes and structs.

For more information visit: http://aspalliance.com/1227_Understanding_Operator_Overloading_in_C.all

 C# has a large set of operators, which are symbols that specify which operations to perform in an expression.

Arithmetic
+ - * / %

Logical (boolean and bitwise)
& | ^ ! ~ && || true false

String concatenation
+

Increment, decrement
++ --

Shift
<< >>

Relational
== != < > <= >=

Assignment
= += -= *= /= %= &= |= ^= <<= >>=

Member access
.

Indexing
[]

Cast
()

Conditional
?:

Delegate concatenation and removal
+ -

Object creation
new

Type information
as is sizeof typeof

Overflow exception control
checked unchecked

Indirection and Address
* -> [] &

For more details visit http://msdn.microsoft.com/en-us/library/6a71f45d(VS.71).aspx

Partial class

Instead of defining an entire class, you can split the definition into multiple classes by using the partial keyword. When the application is complied, the C# complier will group all the partial classes together and treat them as a single class. There are a couple of good reasons to use partial classes. Programmers can work on different parts of a class without needing to share the same physical file. Also you can separate your application business logic from the designer-generated code.

C#
Public partial class Employee
{
      public void DoWork()
      {}
}
  
Public partial class Employee
{
       public void GoToLunch()
       {}
}

 Abbreviated as GAC, the Global Assembly Cache is a machine-wide store used to hold assemblies that are intended to be shared by several applications on the machine. Each computer where the common language runtime (CLR) is installed has a global assembly cache. The global assembly cache stores the assemblies specifically designated to be shared by several applications on the computer.

For more details visit http://www.webopedia.com/TERM/G/Global_Assembly_Cache.htm


To create a strong name key use following code
C:\>sn -k s.snk


Strong name key is used to specify the strong name used to deploy any application in the GAC (Global Assembly Catch) in the system.

 Object Pooling 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.

Object Pool is nothing but a container of objects that are ready for use. 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.

This concept has been better explained in following article
http://www.c-sharpcorner.com/UploadFile/vmsanthosh.chn/109042007094154AM/1.aspx


The name of C# compiler is CSC.

eg. to create the executable of the .cs file you can use
csc File.cs 

This will create File.exe file.

For more details visit: http://msdn.microsoft.com/en-us/library/78f4aasd.aspx


Using statement is used to work with an object in C# that inherits IDisposable interface.

IDisposable interface has one public method called Dispose that is used to dispose off the object. When we use Using statement, we don't need to explicitly dispose the object in the code, the using statement takes care of it. For eg.
Using (SqlConnection conn = new SqlConnection())
{
  
}

When we use above block, internally the code is generated like this
SqlConnection conn = new SqlConnection()
try
{
  
}
finally
{
          // calls the dispose method of the conn object
}


Using statement make the code more readable and compact.

For more details read http://www.codeproject.com/KB/cs/tinguusingstatement.aspx

 NO,because c# doesnot support static block,but it supports static method


When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.

ADO.NET

 SQLClient .NET classes are highly optimized for the .net / sqlserver combination and achieve optimal results. The SqlClient data provider is fast. It's faster than the Oracle provider, and faster than accessing database via the OleDb layer. It's faster because it accesses the native library (which automatically gives you better performance), and it was written with lots of help from the SQL Server team.


• ADO.NET Does Not Depend On Continuously Live Connections
• Database Interactions Are Performed Using Data Commands
• Data Can Be Cached in Datasets
• Datasets Are Independent of Data Sources
• Data Is Persisted as XML
• Schemas Define Data Structures

 DAO is used for database access on windows platform. It creates a work space object in which applications or operations are performed. There are two types of database engines they are Jet database engine and ODBC direct database engine.

 ADO.NET utilizes the power of XML by providing disconnected access to data. This is designed with the help of XML classes in .NET Framework which form the components of single architecture.

 1. Connection object is responsible for creating a connection to the database.
2. Record object represents data which is not from the database.
3. Parameter object represents a sql parameter
4. Stream object is responsible to represent data from a text page or web page.



In order to create a DataView from a DataTable, use instantiate the DataView object by passing DataTable as parameter in the constructor.

eg.
DataView dView = new DataView(dTable);


Yes,

DataAdapter object can accept either DataTable or DataSet as parameter to fill data from database.

eg.
SqlDataAdapter dAd = new SqlDataAdapter();
DataTable dTable = new DataTable();
DataSet dSet = new DataSet();
----
---
dAd.Fill(dTable); // will also work
dAd.Fill(dSet); // will also work
 


We should only use DataSet as parameter when we are expecting more than one result set is being returned from database.

 A linked server configuration enables SQL Server to execute commands against OLE DB data sources on remote servers. Linked Servers is a concept in SQL Server by which we can add other SQL Server to a Group and query both the SQL Server dbs using T‐SQL Statements.
Linked servers offer the following advantages:


1. Remote server access.
2. The ability to issue distributed queries, updates, commands, and transactions on heterogeneous data sources across the enterprise.
3. The ability to address diverse data sources similarly.

With a linked server, you can create very clean, easy to follow, SQL statements that allow remote data to be retrieved, joined and combined with local data. Stored Procedure sp_addlinkedserver, sp_addlinkedsrvlogin will be used add new Linked Server.


increase the execution time out in web.config (or)increase the connection time out in connection string

 Connection pooling enables an application to use a connection from a pool of connections that do not need to be re-established for each use. Once a connection has been created and placed in a connection pool, an application can reuse that connection without performing the complete connection creation process.

 Datagrid is
* one which has advanced features and lets you do lot many things like paging and sorting your data without much effort.
* DataGrid can hold text data, but not linked or embedded objects.


Whereas a DataRepeater is
* which does not have the paging feature but we can do it by coding.
* one which can hold other controls and can embed objects.
* It can embed a Datagrid within it but not viceversa.

Apart from this a Data Repeater
--is used in places where you need more control over the rendering of your data
-- have very flexible templates that give you total control over the formatting of your data


No, it just reads the information from its data source


SqlDataReader object. (Note: Even datasets also use SqlDataReader objects internally for retriving data from database.)


No, it is readonly and forward only control so we can't edit data in repeater control.

C#

 In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.

 A delegate that has multiple handlers assigned to it. Each assigned handler (method) is called.

 A delegate object encapsulates a reference to a method.


1. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.
2. When at least one of the methods in the class is abstract.

 StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created.

 NOTE: This is objective type question, Please click question title for correct answer.


Static:
1)A Static memberdata or a memberfunction can be called without the help of an object.
2)Static members can be called with the help of Classname.

Syntax: classname.staticmember
3)'this ' keyword cannot be used inside a static memberfunction
4)Nonstatic members cannot be used inside a static memberfunction

 Both CopyTo() and Clone() make shallow copy (data is copied) and used for Single Dimension arrays.

Clone() method makes a clone of the original array. It returns an exact length array.

CopyTo() copies the elements from the original array to the destination array starting at the specified destination array index. Note that, this adds elements to an already existing array.

In VB.NET, variables has to be declared earlier, before using Clone or CopyTo methods to store the values. The difference arise on mentioning the size of the array.

While declaring the varaiable that is used for CopyTo method, it should have the size equal to or more than that of the original array.

While declaring the variable that is used for Clone method we need not mention the array size. Eventhough the array size is small, it won't show any error, rather the array size gets altered automatically on cloning. The cloned array size get created equal to the size of the source array.

If value type is used for CopyTo/Clone any change in the values made on them will not get reflected on the original whereas on reference type the change gets reflected.

Below is the code which would throw some light on your understanding.

 Constructor:
-----------------

1. The Constructor is the first method that is run when an instance of a type is created. In visual basic a constructor is always Sub new ().

2. Constructor are use to initialize class and structure data before use. Constructor never returns a value and can be overridden to provide custom initialization functionality.

3. The constructor provides a way to set default values for data or perform other necessary functions before the object available for use.

Destructor:
---------------
Destructors are called just before an object is destroyed and can be used to run clean-up code. You can’t control when a destructor is called.


This is a new feature in C# 3.0. This method allows us to add a new static method to the existing classes.

For example, if we want to validate an Email address using the static method of the string class (built-in) class, we can add an extension method like this.
public static bool IsValidEmail(this string input)
        {
            Regex regEx = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
            return regEx.IsMatch(input);
        }


Notice the parameter passed to above method. Here "this" indicates the string class. Now, we can use above extension method like this.
string myEmail = "me@me.com";
bool IsValidEmailAddress = myEmail.IsValidEmail();


In this case as the format of the email id in myEmail variable is correct so IsValidEmailAddress will be true.



If no class is inhertited, by default a class inherit System.Object.
 Extension method is a new feature in C# 3.0.

Extension methods allow existing classes to be extended without relying on inheritance or having to change the class's source code. This means that if you want to add some methods into the existing String class you can do it quite easily.

Here's a couple of rules to consider when deciding on whether or not to use extension methods:

* Extension methods cannot be used to override existing methods
* An extension method with the same name and signature as an instance method will not be called
* The concept of extension methods cannot be applied to fields, properties or events
* Use extension methods sparingly....overuse can be a bad thing!

For more details, see http://weblogs.asp.net/dwahlin/archive/2008/01/25/c-3-0-features-extension-methods.aspx

 Partial class is a new functionality added in since .NET Framework 2.0 version. It allows to split us to split the definition of once class, struct, interface into multiple source files. Each source file contains a section of definition, and all parts are combined when the application is compiled.

For more detail see http://msdn.microsoft.com/en-us/library/wa80x488(VS.80).aspx

 A Nested classes are classes within classes.

OR

A nested class is any class whose declaration occurs within the body of another class or interface.

For more details see http://www.codeproject.com/KB/cs/nested_csclasses.aspx

 A top level class is a class that is not a nested class.

See what is nested class http://www.dotnetfunda.com/interview/exam281-what-is-nested-class.aspx

 NOTE: This is objective type question, Please click question title for correct answer.

 Garbage collection is a mechanism that allows the computer to detect when an object can no longer be accessed. It then automatically releases the memory used by that object (as well as calling a clean-up routine, called a "finalizer," which is written by the user). Some garbage collectors, like the one used by .NET, compact memory and therefore decrease your program's working set.


An application domain (often AppDomain) is a virtual process that serves to isolate an application. All objects created within the same application scope (in other words, anywhere along the sequence of object activations beginning with the application entry point) are created within the same application domain. Multiple application domains can exist in a single operating system process, making them a lightweight means of application isolation.

An OS process provides isolation by having a distinct memory address space. While this is effective, it is also expensive, and does not scale to the numbers required for large web servers. The Common Language Runtime, on the other hand, enforces application isolation by managing the memory use of code running within the application domain. This ensures that it does not access memory outside the boundaries of the domain. It is important to note that only type-safe code can be managed in this way (the runtime cannot guarantee isolation when unsafe code is loaded in an application domain).

 This is a new feature in C# 3.0. This enable use to create a type/class on-the-fly at compile time.
For example
var emp = new { Name = "Sheo", Gender = "Male", Active = true };
In this case a new type will be created on the fly that will have Name, Gender, and Active as public property and its backing field like _Name, _Gender, _Active.

This is especially useful when we want to receive data from other object or iterate through a collection and set values and do not want to create a class just to hold the data. Note that anonymous types are just a placeholder, we can't customize its behavior or add methods inside it.


This is the new feature in C# 3.0. This enable us to declare a variable whose type is implicitly inferred from the expression used to initialize the variable.

eg.

var age = 10;

Because the initialization value (10) of the variable age is integer type of age will be treated as integer type of variable. There are few limitation of the var type of variables.

They are:

#. They can't be initialized as null.
#. They need to be declared and initialized in the same statement.
#. They can't be used as a member of the class.

 Building a shared assembly does involve working with cryptographic keys. Only the public key is strictly needed when the assembly is being built. Compilers targeting the .NET Framework provide command line options (or use custom attributes) for supplying the public key when building the assembly. It is common to keep a copy of a common public key in a source database and point build scripts to this key. Before the assembly is shipped, the assembly must be fully signed with the corresponding private key. This is done using an SDK tool called SN.exe (Strong Name).

Strong name signing does not involve certificates like Authenticode does. There are no third party organizations involved, no fees to pay, and no certificate chains. In addition, the overhead for verifying a strong name is much less than it is for Authenticode. However, strong names do not make any statements about trusting a particular publisher. Strong names allow you to ensure that the contents of a given assembly haven't been tampered with, and that the assembly loaded on your behalf at run time comes from the same publisher as the one you developed against. But it makes no statement about whether you can trust the identity of that publisher.


Data Reader is connected, read only forward only record set.
Dataset is in memory database that can store multiple tables, relations and constraints; moreover dataset is disconnected and is not aware of the data source.


Attributes are a mechanism for adding metadata, such as compiler instructions and other data about your data, methods, and classes, to the program itself. Attributes are inserted into the metadata and are visible through ILDasm and other metadata-reading tools. Attributes can be used to identify or use the data at runtime execution using .NET Reflection.


String is an object (Reference Type).

Easy Way To Pay

Sign up for PayPal and start accepting credit card payments instantly.

Earn While Searching