Showing posts with label Questions. Show all posts
Showing posts with label Questions. Show all posts

Saturday, 8 June 2013

C# Interview Questions

41. How can we achieve multiple inheritance in c#?
a ) Using interfaces.

42. An interface is a value type or reference type?
a ) An interface is a reference type.

43. Does an interface extend classes?
a ) No

44. Can we write constructors and destructors for an interface?
a ) No.

45. What are the default modifiers of members of an interface?
a ) Public and abstract

46. What are the differences between an abstract class and an interface?
a ) Abstract class
1. it can contain implementation to some methods.
2. we can apply access modifiers to one or more methods in an abstract class
3. a class can not inherit more than one abstract class
4. an abstract class can have fields and constants defined
Interface
1. it just contains declarations. No implementation for any method.
2. we can not apply access modifiers to methods inside an interface
3. a class can inherit more than one interface
4. interface does not contain any field definition.

47. Can an interface is implemented by any number of classes?
a ) Yes.

48. What are the types of polymorphism?
a ) 2 types
1. operation polymorphism
2. inclusion polymorphism

49. How we achieve operation polymorphism and inclusion polymorphism?
a ) Operation polymorphism is achieved using overloaded methods and operators
And inclusion polymorphism is achieved using virtual functions.

50. what do you mean by compile time polymorphism?

a ) It is a process of selecting and binding the appropriate method to the object for a particular call at compile time.

Previous                                         Next


C# Interview Questions

31. What are the inheritance types?
a ) 1. single level inheritance
2. multi level inheritance
3. multiple inheritance
4. hierarchical inheritance

32. Can we inherit the private members of a class
a ) Yes. But they are not accessible.

33. Why we use the keyword virtual?
a ) When you want to override a method of base class in derived class you should use this virtual keyword to the method in base class

34. Why we use override keyword?
a ) When you want to override a method of base class in derived class you should use this override keyword to the method in derived class

35. What are the abstract classes?
a ) Abstract classes are the classes for which we can not create objects. Means an abstract class can not be instantiated.

36. What are abstract methods?
a ) Abstract methods are the methods which does not contain their body part means they does not provide any implementation.

37. What are the properties of abstract methods?
a ) 1. they do not contain body part.
2. their definition/implementation should be given in non-abstract classes by overriding that method.
3. we can not use static modifier to it.

38. What are the sealed classes?
a ) If you want to prevent a class from being inherited you can use this keyword sealed to that particular class

39. What are sealed methods?
a ) A sealed method is a method which can not be overridden by its derived class.

40. Does a sealed class is an abstract class? Why?
a ) No a sealed class is not an abstract class. Because we can’t inherit a sealed class but we can inherit an abstract class.

Previous                                         Next


C# Interview Questions

21. What are the properties of constant members?
a ) 1. They should use the modifier ‘ const’
2. Their value should be given when they are defined (it can’t be changed later)
3. They are implicitly static.

22. Why we use this keyword?
a ) This is used to distinguish local and instant variables that have the same name.

23. Does a copy of a static variable is created every time a class is instantiated?
a ) No.

24. What is a partial class?
a ) A partial class is a class which resides in multiple files. It should use 'partial' keyword. Generally it is used in situations where multiple developers need acess to the same class.

25. What is the name of the class from which all .net classes are derived?
a ) System.Object

26. Does c# support global variables?
a ) No. all declarations must be done inside a class.

27. Differences between property and indexer?
a ) Property
A property can be static member
The get accessor of a property corresponds to a method with no parameters
Indexer
An indexer is always an instant member
The get accessor of an indexer corresponds to the same formal parameter list as the indexer.

28. Differences between overloading and overriding?
a ) Overloading
1. used we want a method with more than one definition with in the same scope
2. in overloading, methods will have same name but different number, types, order of arguments.
Overriding
1. this is used when we have parent, child classes.
2. in overriding , methods will have same name with same arguments and same return type.

29. what is the order of the constructor execution in inheritance?
a ) They are executed from top(parent class) to bottom(child class)

30. what is the order of the destructors execution in inheritance?
a ) They are executed from bottom(child class) to top(parent/base class)


Previous                                         Next


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


C# Interview Questions

1. What are the main properties of object oriented programming?
 There are mainly 3 properties
  1. Encapsulation/Abstraction
  2. Inheritance
  3. Polymorphism
2. What is encapsulation?
a ) This gives a way to hide the internal details of an object from its users.

3. What is inheritance ?
a ) It provides a way to build/create new classes using existing classes.

4. What is polymorphism?
a ) It provides a way to take more than one form.

5. What is a constructor?
a ) Constructor enables an object to initialize itself when it is first created.

6. What are the properties of a constructor?
a ) They are
  1. They should have the same name as that of a class
  2. They do not specify a return type.
  3. we can use access modifiers to constructor.
7. How many types of access modifiers are there ?
a ) 5 types
  1. Private
  2. Public
  3. Protected
  4. Internal
  5. Protected Internal
8. What access modifiers we can use for a class?
a ) We can use 2 access modifiers
  1. Public
  2. Internal
9. What is the default access modifier of a class?
a ) It is Internal

10. What is the default access modifier for class members?
a ) It is Private

Directives for Asp.Net Web Pages

Directives
---------------
Directives are used to specify the settings used by the page or usercontrol compilers to process pages or usercontrol files

There are 11 types of directives

1.@Page: This is used to define page specific attributes. It is used only in .aspx files

2.@Control: This is used to define Control specific attributes. It is used only in .ascx files

3.@Master: This is used to define masterpage specific attribute. It is used only in .master files

4.@Import: This is used to import a namespace in to the current page or usercontrol

5.@Register: This is used to render usercontrols and custom server controls in to a current page or usercontrol

6.@Assembly:: This is used to link a page or usercontrol in to current page or usercontrol

8.@Implements: This is used to implement a specific .Net framework Interface in to current page or
usercontrol

9.@Outputcache: This is used to apply cache techniques in to the current page or usercontrol

10.@MasterType: This defines a class or virtual path used to type the master property of a page

11.@Previouspagetype: This is used to create a strongly typed reference to the source page from the target of a cross page posting.