Monday, March 9, 2009

C# InterviewQuestions- Part 5

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.

Monday, March 2, 2009

C# InterviewQuestions- Part 4

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.