Saturday 8 June 2013

C# Interview Questions

11. Can we use access modifier on static constructor?
a ) No

12. How many static constructors we can declare for a single class?
a ) A class can have only one static constructor.

13. What is method overloading?
a ) It is a process of creating methods that have the same name but with different parameter lists and different definitions. This method overloading is used when you want your methods to do same tasks but using different input parameters.

14. What happens when we use ‘private’ modifier to a constructor of a class?
a ) When we declare a constructor of a class as private then we can’t create a objects of that class and we can not use that class as a base class for inheritance

15. Can we overload constructors?
a ) Yes

16. What are instant variables?
a ) Class variables are known as instant variables. Instant variables are different for each object and they are accessed using the objects. When ever a class is instantiated a new copy of the each of the instant variable is created.

17. What are static variables?
a ) These are also known as class variables. Static variables are common for all objects of a class. Only one copy of static variables will be created for all the objects of a class.

18. What are the differences between structure and class
a ) Structure:
It is value type
It is stored on stack
Does not support inheritance
Suitable for small data structure
Class:
It is reference type
It is stored on heap
Supports inheritance
Suitable for complex data structures

19. What is a value type? Give examples
a ) It stores value directly. Value types are stored on stack. Separate memory will be given for each instant of a value type.
Ex: int, float, char, struct

20. What are reference type?
a ) It stores a reference to the value. They are stored on heap.
Ex: class, string, array.


Previous                                         Next



EmoticonEmoticon