C# Interview questions- HCL
I have recently attended the interview in HCL . Following are some of the questions asked in C#. They have covered C#, Asp.net & SQL Sever and also some questions asked in Design patterns. Interview went for around 1 hour.
I have posted only C# questions in this article. Will cover the other area of questions in the following articles.
1. What is Overriding?
Overriding is a concept where a method in a derived class uses the same name with the same return type and also the same arguments as a method in its base class. In other words, if the derived class contains its own implementation of the method rather than using the method in the base class, the process is called overriding
2.What are events and delegates?
An event is a message sent by a control to notify the occurrence of an action. However it is not known which object receives the event. For this reason, .NET provides a special type called Delegate which acts as an intermediary between the sender object and receiver object
3.Can multiple catch blocks be executed?
No, Multiple catch blocks can't be executed. Once the proper catch code executed, the control is transferred to the finally block and then the code that follows the finally block gets executed.
4.difference between public, static and void?
All these are access modifiers in C#. Public declared variables or methods are accessible anywhere in the application. Static declared variables or methods are globally accessible without creating an instance of the class. The compiler stores the address of the method as the entry point and uses this information to begin execution before any objects are created. And Void is a type modifier that states that the method or variable does not return any value.
5.difference between ref & out parameters?
An argument passed as ref must be initialized before passing to the method whereas out parameter needs not to be initialized before passing to a method
6. Can “this" be used within a static method?
We can't use ‘This' in a static method because we can only use static variables/methods in a static method.
7.What is difference between constants and read-only?
Constant variables are declared and initialized at compile time. The value can't be changed after wards. Read-only variables will be initialized only from the Static constructor of the class. Read only is used only when we want to assign the value at run time.
8. What is an interface class?
Interface is an abstract class which has only public abstract methods and the methods only have the declaration and not the definition. These abstract methods must be implemented in the inherited classes.
9. What are value types and reference types?
Value types are stored in the Stack whereas reference types stored on heap.
Following are some of the Value types:
int, enum , byte, decimal, double, float, long
Reference Types:
string , class, interface, object.
10. Different categories of inheritance?
There are 4 types of Inheritance in Object Oriented Programming and they are as follows
(i)Single inheritance : Have one base class and one derived class.
(ii)Hierarchical inheritance : Have one base class and multiple derived classes of the same base class.
(iii)Multilevel inheritance : Have a class derived from a derived class.
(iv)Multiple inheritance : Have several base classes and a derived class.
11. Difference between constants, readonly and, static ?
(i) Constants: Value can't be changed.
(ii) Read-only: Value will be initialized only once from the constructor of the class.
(iii)Static: Value can be initialized once.
12. What is multi cast delegates?
Each delegate object holds reference to a single method. However, it is possible for a delegate object to hold references of and invoke multiple methods. Such delegate objects are called multicast delegates or combinable delegates.
13.What is data encapsulation?
Data encapsulation, also referred to as data hiding, is the mechanism whereby the implementation details of a class are kept hidden from the user. The user can only perform a restricted set of operations on the hidden members of the class by executing special functions called methods.
14.Is it possible to override private virtual methods?
No. Private methods are not accessible outside the class.
15.Can you store multiple data types in System.Array?
No.
16. What's the difference between the System.Array.CopyTo() and System.Array.Clone()?
The first one performs a deep copy of the array, the second one is shallow.
Thanks...It's useful for me...