Google

Tuesday, October 9, 2007

Interview questions for .Net for Freshers

What is Class
A user-defined data structure that groups properties and methods. Class doesn’t occupies memory.

What is Object
Instance of Class is called object. An object is created in memory using keyword “new”.

What is .Net Platform?
Microsoft .NET is a software development platform based on virtual machine architecture.
    Dot Net Platform is:
  • Language Independent – dot net application can be developed different languages (such as C#, VB, C++, etc.)
  • Platform Independent – dot net application can be run on any operating system which has .net framework installed.
  • Hardware Independent – dot net application can run on any hardware configuration It allows us to build windows based application, web based application, web service, mobile application, etc.
What is .Net Framework?
.Net Framework provides a foundation upon which .net application and xml webservices are built and executed.

Two main Components of .Net Framework
  • 1. Common Language Runtime
  • 2. Base Class Library.

Difference between Struct and Class
  • Struct are Value type and are stored on stack, while Class are Reference type and are stored on heap.
  • Struct “do not support” inheritance, while class supports inheritance. However struct can implements interface.
  • Struct should be used when you want to use a small data structure, while Class is better choice for complex data structure.

What is the difference between instantiating structures with and without using the new keyword?
When a structure is instantiated using the new keyword, a constructor (no-argument or custom, if provided) is called which initializes the fields in the structure. When a structure is instantiated without using the new keyword, no constructor is called. Hence, one has to explicitly initialize all the fields of the structure before using it when instantiated without the new keyword.


What do you mean Encapsulation in oops
Wrapping up of data and function into a single unit is known as Encapsulation.
Example of encapsulation: class.

How to use Properties in .Net
Attribute of object is called properties. Eg1:- A car has color as property.
Example:
private string m_Color;;

public string Color
{
get
{
return m_Color;
}
set
{
m_Color = value;
}
}

Car Maruti = new Car();
Maruti.Color= “White”;


Console.Write(Maruti.Color);



Isn't it better to make a field public than providing its property with both set { } and get { } block? After all the property will allow the user to both read and modify the field so why not use public field instead? Motivate your answer.

Not always! Properties are not just to provide access to the fields; rather, they are supposed to provide controlled access to the fields of our class. As the state of the class depends upon the values of its fields, using properties we can assure that no invalid (or unacceptable) value is assigned to the fields.
Example:
private int age;

public int Age
{
get
{
return age;
}
set
{
if(value <> 100)
//throw exception
else
age = value;
}
}

Note : All these questions are taken from dailyfreecode.com

No comments: