Some Interview Questions for .Net technology


This will help you to prepare technically using these questions. In every interview they will start with OOPS concept. Here I will list out the questions asked by technical round. What is Object Oriented Programming ? What's a Class ?

.Net questions with OOPS



1.What is Object Oriented Programming ?
2.What's a Class ?
3.What's a Object ?
4.What's the relation between Classes and Objects ?
5.What are different properties provided by Object-oriented systems ?
6.Can you explain different properties of Object Oriented Systems?
7.what is Polymorphism?
8.What is meant by Binding?
9.What is meant by static binding?
10.What is meant by Dynamic binding?
11.Define Modularity?
12.What is meant by Persistence?
13.What is friend function?
14.What is a virtual function?
15.What is a ternary operator?
16.What is exception handling?
17.What are the various types of constructors?
18.What is a copy constructor?
19.What is Access Modifier in OOPS?
20.What is Compile Time Polymorphism in OOPS?
21.can we implement multiple inheritance by using interfaces in C#.net?
22.How a pointer stores address?
23.Difference between Object Base and Object Oriented ?
24.Main Difference between Method and function?
25.What is the difference between a struct and a class in C#?
26.If you are required to call a non-static method in static method then how will you do this?
27.If you want to restrict user to make only one object in the entire application usage how will you achieve this?

28.What's difference between Association , Aggregation and Inheritance relationships?
29.How can we achieve inheritance in VB.NET ?

30.What are abstract classes ?
31.What's a Interface ?
32.What is difference between abstract classes and interfaces?
33.What is a delegate ?
34.What are event's ?
35.Do events have return type ?
36.Can event's have access modifiers ?
37.Can we have shared events ?
38.What is shadowing ?
39.What's difference between Shadowing and Overriding ?
40.What's difference between delegate and events?
41.If we inherit a class do the private variables also get inherited ?
42.What are different accessibility levels defined in .NET ?
43.Can you prevent a class from overriding ?
44.What's the use of "MustInherit" keyword in VB.NET ?
45.What is Dispose method in .NET ?
46.Whats the use of "OverRides" and "Overridable" keywords ?

47.Why can not you specify accessibility modifier in Interface ?
48.What are similarities between Class and structure ?
49.What's the difference between Class and structure's ?
50.What does virtual keyword mean ?
51.What are shared (VB.NET)/Static(C#) variables?


52.Where are all .NET Collection classes located ?
53.What is ArrayList ?
54.What's a HashTable ?
55.What's difference between HashTable and ArrayList ?
56.What are queues and stacks ?
57.What is ENUM ?
58.What is nested Classes ?
59.What's Operator Overloading in .NET?
60.In below sample code if we create a object of class2 which constructor will fire first ?
61.What's the significance of Finalize method in .NET?
62.Why is it preferred to not use finalize for clean up?
63.How can we suppress a finalize method?
64.What's the use of DISPOSE method?
65.How do I force the Dispose method to be called automatically, as clients can forget to call Dispose
method?
66.In what instances you will declare a constructor to be private?
67.Can we have different access modifiers on get/set methods of a property ?
68.If we write a goto or a return statement in try and catch block will the finally block execute ?

69.What is Indexer ?
70.Can we have static indexer in C# ?
71.In a program there are multiple catch blocks so can it happen that two catch blocks are executed ?
72.What is the difference between System.String and System.StringBuilder classes?
73.What is sealed class?


Comments

Author: Ultimaterengan24 May 2013 Member Level: Gold   Points : 0

Really good collection...

Author: Pawan Awasthi24 May 2013 Member Level: Gold   Points : 2

Hai Rani,
Thanks for posting 70+ questions related to the OOPs concept. These questions will definitely helpful for those who want to refresh the OOPs concept in less time. They can check their knowledge by these questions.

Author: Pawan Awasthi25 May 2013 Member Level: Gold   Points : 10

Hi Rani Priya,
Thanks for posting good 70+ questions of OOPs. These questions will really help to those who are preparing the OOPs concepts in the last minute before going to attend the interview.
Below I am trying to provide the answers to each of the question.
The system is not allowing to post more text under one response so I have split the question in to multiple sections and posting them.

.Net questions with OOPS

1. What is Object Oriented Programming?
Ans. Based on the Style of programming, languages can be divided in to 3 types:-
a. Procedural Languages (e.g. ALGOL-1954)
b. Structural Languages (e.g. C – 1970 , BASIC, COBOL)
c. Object Oriented Languages (e.g. C++, Java, C#, VB.Net)
When a language follows the following features or rules then it is called as Object Oriented Language-
• Encapsulation
• Abstraction
• Polymorphism
• Inheritance
Including this, the language should support the Class and Object feature also.

2. What's a Class?
Ans. Class is a Logical representation which provides the structure for objects. As per the .Net Technology, a class is the collection of –
• Fields
• Properties
• Methods
• Events
Field- Private data of a class I called as field.
Property- It defines shape of an object.
Method- “What an object can do?” is defined by method. It provides the way to interact with the object’s state.
Event- Action on the object is called as Event.

3. What's a Object?
Ans. Instance of the class is called as object. By default event class inherits from System.Object class
By default , a class have 4 methods-
GetType()- Returns the type of Class Name
Equals()- To copare the objects
GetHashCode()- Return starting address in the heap memory
ToString()- to convert to string.

4. What's the relation between Classes and Objects?
Ans. Instance of a class is called as object. Class is the blueprint and doesn’t contain any memory. Object contains memory.
Class Object
1. Logical Physical
2. Occupy less memory Occupy more memory
3. No Life time Have Life time- Birth Time(Constructor) and Death Time(Destructor)
MyClass objClass = new MyClass();
Here objClass is the object of the Class MyClass.

5. What are different properties provided by Object-oriented systems?
Ans. Object Orient System is based on 4 Pillars which are backbone of any system to be Object oriented. These Pillars are
• Encapsulation
• Abstraction
• Polymorphism
• Inheritance

6. Can you explain different properties of Object Oriented Systems?
Ans. Below are the explanation of each of the Object orient Systems:
1. Encapsulation – It is the concept of Data Hiding. It hides the unnecessary details of implementation from the class object. By this rul of OOPs, the object’s internal data should not be accessible directly through the object instances. To implement this concept, we use the Access Specifiers(Public, private, Protected etc).
2. Abstraction- Abstraction is the behavior to get the required functionality in the child class. So we don’t matter whatever is written in the base class. We only need to force the child class to implement my required functionality.
Abstract keyword is used to get the abstraction behavior.
3. Polymorphism- Using the same method in multiple forms is called as Polymorphism. In the Polymorphism, the method name is same but their prototype can be different.
E.g. Add(), Add(int a, int b),Add(int a, int b, int c)
4. Inheritance- Inheriting the parent class behavior to the child class is called as inheritance. Also Deriving the features of the one class(base class) to the other class (child class) is also called as inheritance. Inheritance leads to code reusability, and saves memory, reduce the complexity and increase the easy maintainability of the code. There are 5 types of inheritance:-
• Single Inheritance
• Multilevel Inheritance
• Multiple Inheritance
• Hierarchical Inheritance
• Hybrid Inheritance

7. What is Polymorphism?
Ans. Polymorphism is to use the same function in many forms. The polymorphism is of 2 types-
a. Classical polymorphism (Overloading)
b. AdHoc polymorphism (Overriding)
When the runtime (CLR) find the behavior of class members at the runtime of the program, it is called as the AdHoc polymorphism or Overriding.in this the method name is same but they are implemented in the different class. We use virtual keyword in the base class method to be overrides in the child class using the override keyword.
e.g.
public class MyClass
{
Public int Add(int a, int b)
{
Return a+b;
}
Public int Add(int a, int b, int c)
{
Return a+b+c;
}
}
When the runtime (CLR) find the behavior of class members at the compilation of the program, it is called as the Classical polymorphism or Overloading.in this the method name is same but there prototypes (parameters) are different and it is implemented in the same class.
e.g.
Public class MyBaseClass
{
Public virtual void Show(string message)
{
Console.WriteLine(“Your message is : ”+ message);
}
}
Public class MyChildClass: MyBaseClass
{
public override void Show(string message)
{
Console.WriteLine(“Your new message is : ”+ message);
}
}


8. What is meant by Binding?
Ans. Binding is the way by which the class objects gets associated.
There are 2 types of bindings:-
• Early Binding- Also called as Static Binding
• Late Binding - Also called as Dynamic Binding

9. What is meant by static binding?
Static binding is a binding type where the association of the class object is done during the compilation of the program. It means while compilation of the application, the run-time (CLR) finds the behavior of such class objects. For example- Overloading the example for the static binding where the methods which are overloaded are defined and associated during the compilation.
This binding is also called as Early binding. It is good in such scenarios where the objects are heavy so if there is any error, it will show during the compilation and can be fixed before running the application.

10. What is meant by Dynamic binding?
Dynamic binding is a binding where the class object gets associated in runtime of the application based on the preferences and requirements. If an object is needed then only it will be associated else it will not be included in the run-time. Its good in such scenarios where we have very less dependencies between the object as while loading, it should load only those objects which are necessary and not load the other objects. This binding is also called as Late Binding. So the object is created only when required is the main concept of the late binding..
Cont…

Author: Ranipriya25 May 2013 Member Level: Gold   Points : 0

Thank you very much

Author: Pawan Awasthi26 May 2013 Member Level: Gold   Points : 10

11. Define Modularity?
Ans. Modularity in OOPs means the design of the program should be in such a way so that it can be broken in to pieces or modules and then each module can build separately. It leads to the less interdependence between the modules and the whole program can be structured and completed in the perfect manner. Many people can work separate modules and all modules can be combines at the end to get the full program.

12. What is meant by Persistence?
Ans. The way through which the data is active in different executions of the program during the execution of the program. By using the Persistence feature the execution mode data can be kept alive during the multiple execution of the program.

13. What is friend function?
Ans. A special type of functions which can access the private data of a class. This is the loophole in C++ programming. These functions defines outside of the class and can call the other class members.
For more details, follow the below link:
http://www.fredosaurus.com/notes-cpp/oop-condestructors/friendfunctions.html

14. What is a virtual function?
Ans. Virtual functions are the special type of function which has the capability to redefine in the child classes and they can force the runtime to get the overridden method of the child class rather than calling to the base class method. These methods can be redefined with the same structure in the child classes.
e.g.
class Parent
{
public virtual void Show()
{
Console.WriteLine("Hello Parent");
}
}

class Child : Parent
{
public override void Show()
{
Console.WriteLine("Hello Child");
}
}
Now we can create the object of the child class and call its method. By default it will take the child class definition to be executed as:
class Program
{
static void Main()
{
Child c= new Child();
c.Show();
}
}


15. What is a ternary operator?
Ans. The ternary operator is used for testing a condition. It mainly compares two values. In result it gets the third value which depends upon the result of the comparison. This is the shortcut of if..else statements.
e.g.
int result= 0;
if(a==10)
{
Result = 10;
}
Else
{
Result= 20;
}
Now the same we can write in a single line using ternary operator as:
int result = (a ==10)?10:20;

16. What is exception handling?
Ans. Exception I the runtime condition which stops execution of a program abnormally. To support exception, C# provides the structured exception handlers. .Net Provides Try..Catch..Finally keywords for handling exceptions.
Exception is the base class for all the exceptions. There are 2 types of exceptions-
• Runtime Exceptions- System Defined
• Application Exceptions- User Defined
When an exception is expected, we need to write the code under Try block. Try must be followed with the Catch or Catch with Finally or Try ..Catch and Finally.
One and Only one Finally block can exists with Try and Catch.
Finally Block always executes whether the Exception occurred or not.

17. What are the various types of constructors?
Ans. There are 3 types of constructor:
• Default constructor
• Parameterized constructor
• Copy Constrictor

18. What is a copy constructor?
Ans. This concept is not in .net. It’s in C++ and in Java. Mainly the Copy constructor is used when we have an object and wants to copy the object from existing objects. Here in C#, we need to write the method to copy all the objects from the existing object.
For more details follow the below link:
http://msdn.microsoft.com/en-us/library/ms173116(v=vs.80).aspx

19. What is Access Modifier in OOPS?
Ans. Access Specifies or Access Modifiers defines the accessibility with in the class and methods. In C#, there are 5 types of Access Modifiers:
• Public – Accessed by any subclass by object instance inside or outside of the assembly.
• Protected- Accessed inside as well as to the child class. Scope it limited to the child class.
• Private- Accessible only in the current class where defines. Not accessible to outside of the current class.
• Internal- Accessible inside the class as well as outside of the class by instance but not outside of the assembly.
• Protected internal- Accessible inside the class as well as outside the class and the class derived from the current class. But the scope is limited to the current assembly.

20. What is Compile Time Polymorphism in OOPS?
Ans. When the runtime (CLR) find the behavior of class members at the compilation of the program, it is called as the Classical polymorphism or Compile Time Polymorphism or Overloading.in this the method name is same but there prototypes (parameters) are different and it is implemented in the same class.
e.g.
Public class MyBaseClass
{
Public virtual void Show(string message)
{
Console.WriteLine(“Your message is : ”+ message);
}
}
Public class MyChildClass: MyBaseClass
{
public override void Show(string message)
{
Console.WriteLine(“Your new message is : ”+ message);
}
}

Cont…

Author: Pawan Awasthi01 Jun 2013 Member Level: Gold   Points : 10

Cont…

21. Can we implement multiple inheritances by using interfaces in C#.net?
Ans. Yes, we can implement multiple inheritance using interfaces in C#. Multiple Inheritance doesn't support in C# because the runtime (CLR) can’t decide that from which base class the method to be inherited in case the same method signatures are there in both the base class.
e.g
class A
{
Public void Show()
{
Console.WriteLine(“Hello”);
}
}
Class B
{
Public void Show()
{
Console.WriteLine(“World”);
}
}
Class C: A, B
{
// Error will be thrown
}
This can be implemented by using Interfaces as:
Interface IA
{
void Show();
}
Class C: B,IA
{
Public void IA.Show()
{
Consolw.WriteLine(“Hello”);
}
}
Now when the object will be created, we can get the Show() method based on the Interface reference.

22. How a pointer stores address?
Ans. A Pointer is basically a variable which is used to store the address of another variable. It doesn't store the whole address; instead it stores only the first byte of the address. We can find the next bytes based on the size of the variable.
Lets say there is an integer which we want to keep through the pointer reference. The pointer will keep the first byte as the first address and then as the integer is of 4 bytes then we can add 3 more bytes to get the complete address.

23. Difference between Object Base and Object Oriented?
Ans. Object Based is the language which doesn't support Inheritance as it is the abstract member and not support the class objects. E.g. VB 6.0
Object oriented language supports the inheritance and polymorphism concepts because of the class and objects. E.g. .Net, Java

24. Main Difference between Method and function?
Ans. A function is the code which is called by its name. We can pass the data to it for the operations (i.e. passing parameter) and can return data or value. The parameters which are passed to the functions are explicit.
A method is the code which is also called by name but it is always associated with an object. It is similar to the function except it is implicitly passes the parameters object which it was called. Also operations can be performed by passing the parameters which are contained in the class. So we can pass the instance of the class in the method.

25. What is the difference between a struct and a class in C#?
Ans. There are many differences between the class and struct:
• Structs are value types while the class is reference type.
• As the Structs are value type and all value types are inherit from the class System.ValueType while the class is reference type and all reference types are inherited from Sysem.Object.
• When the value is assigned to the struct, it directly creates a copy of the value while the class object is kept as the reference and not the value.
• We can perform the operations like Boxing and unboxing to convert the struct type to class object.
• Initialization is not support Instance field declarations for a struct are not permitted to include variable initializes.
• Struct support parameterized constructor while class can support parameter less constructors.
• We can’t declare destructor for the struct while we can create the destructor for the class.

26. If you are required to call a non-static method in static method then how will you do this?
Ans. Directly we can’t call the non-static method inside the static method. For this, you can create the object of the method and then you can call the method by the class name as:
public class MyClass
{
public void MyMethod()
{
}

public static void MyStaticMethod()
{
MyClass objClass = new MyClass();
objClass.MyMethod();
}
}


27. If you want to restrict user to make only one object in the entire application usage how will you achieve this?
Ans. We can use the Singleton class object which will allow maximum one instance. In this class object,
public sealed class DemoClass
{
public static readonly _instance = new DemoClass();
public static readonly Instance
{
get
{
return _instance;
}
}
DemoClass()
{
}
}

28. What's difference between Association, Aggregation and Inheritance relationships?
Ans. The Association, Aggregation and Inheritance are the concepts of the OOPs which can be associated with the class objects.
When the objects are having the common structure or if they are similar then we can associate them using the Association. So the relationship between the common structure or common behavior is called as Association.
e.g. Employee ??Manager Here Manager is also an employee

While the Aggregation is “a part of” relationship.
e.g. Student is “a part of” college.
Inheritance is the concept where one class objects can be inherited to another class. It has “is a” and “has a” relationships. The derived class can inherit the parent class behaviors and the characteristics.
Example:
A specialized student can be inherited from the student class.

29. How can we achieve inheritance in VB.NET?
Ans. In Vb.Net Inherits keyword is used to inherit the base class members to the derived classes.
Public Class BaseClass
Public val1 As Integer = 1
Public Function val() As Integer
Return val1
End Function
End Class

Public Class DerivedClass
Inherits BaseClass
Public val As Integer = 10
Public Function add() As Integer
Return val + val1
End Function
End Class

30. What are abstract classes?
Ans. When the class doesn't provide the full functionality then we can declare the class as abstract class.
Collection of the Abstract (Incomplete) and Concrete (complete) methods is called as the Abstract class. If there is at least one abstract method in a class, the class must be abstract class.
When there is the similar behavior, we can use the abstract class.
e.g. We want to calculate the area of few component. As this is not generic to the application. We have only few component- like Circle, Ellipse, parabola, Hyperbola, Triangle etc.
So we can create an abstract class and implement it like below:
public abstract class MyAbstractClass
{
// some other concrete members
public abstract void Area();// abstract member
}
Now in the child class, let’s say i have a circle class and want to calculate the area of the circle:
pyblic class Cicle: MyAbstractClass
{
public override void Area()
{
// calculate the area of the circle
}

}
In the similar fashion, we can calculate the area of other shapes.

Cont…

Author: naveensanagasetti14 Jun 2013 Member Level: Gold   Points : 0

Hi Pawan,

Thanks for sending Answers for all questions. These are the basic questions in OOPs concept.I hope it helps to freshers also.

Author: sushma rana29 Jun 2013 Member Level: Bronze   Points : 0

thanks this post is really helpful......



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: