Monday, July 13, 2009
C# InterviewQuestions- Part 9
a ) If you want to pass a parameter by reference you should use the keyword ref
82. If an out parameter is not assigned a value with in the body of the function does that method complile?
a ) No. it won't compile
83. How can you make write a read only property?
a ) A property can made a read only by omitting the set accessor from the property defination.
84. When a static constructor is executed?
a ) It is executed when the class is loaded.
85. How many preprocessor directives exists in c#?
a ) They are #define, #undef, #if, #elif, #else, #endif, #error, #warning, #region, #endregion, #pragma etc
86. When an instance constructor is executed?
a ) It is executed when an instance is created.
87. Where you can assign values to a read only field?
a ) We can assign inside a constructor
88. Why we use the sixeof operator?
a ) If we want to know the size of any data type you can use sizeof operator.
89. What are the disadvantages of distructors in c#?
a ) 1. They are non deterministic. means there is no way to know when an object's destructor will actually execute.
2. Implementation of destructor delays the final removal of an object from memory. means objects that have destructors are removed in 2 passes. in the 1st pass only the destructor will be called with out removing object and then the 2nd pass removes the object, which is time taking and which may effect the performance.
90. What is the default access modifier of an interface members?
a) public
Thursday, July 2, 2009
C# InterviewQuestions- Part 8
-----------------------------
71. Can we declare an abstract method in non abstract class?
a ) No. it can declared only in abstract classes
72. Can we use static or virtual keywords to an abstract method?
a ) No
73. Can an interface extend a class?
a ) No. it can’t extend classes.
74. Is it necessary that the direct base class of a derived class must be at least as accessible as the derived class itself?
a ) Yes.
75. What is the keyword that is used to invoke the constructor method of the super class?
a ) It is the keyword “base”.
76. What is an enumeration?
a ) An enumeration is a user-defined integer type which provides a way for attaching names to numbers.
77. What is boxing?
a ) Conversion of value type to object type (reference type) is known as boxing
78. What is unboxing?
a ) Conversion of object type to value type is known as unboxing.
79. What are the categories of variables that are automatically initialized to their default values?
a ) They are
1. Static variables
2. Instance variables
3. Array elements
80. What is the scope of a variable?
a ) Scope of a variable is the region of code with in which the variable can be accessed.
Tuesday, June 23, 2009
C# InterviewQuestions- Part 7
----------------------------
61. Can private virtual methods be overridden ?
a ) No. we can not access private methods in inherited classes.
62. Can we inherit multiple interfaces?
a ) yes. In c# multiple inheritance is achieved through interfaces.
63.How can a method be overloaded?
a ) a method can be overloaded by creating a method with the same name but with different parameter order, data types and number
64. Will finally block get executed if the exception had not occurred?
a ) Yes. Finally block always gets executed regardless of an error.
65. Can multiple catch blocks be executed ?
a ) No. once the appropriate catch code is fired control transfer to the finally block then continues with the rest of the code.
66. What is the accessibility level of a protected variable?
a ) It is available to the classes in the same name space.
67. Can you override private virtual methods
a ) No.
68. Can we inherit multiple interfaces?
a) Yes. We can’t inherit multiple classes but we can inherit multiple interfaces.
69. Can we use virtual keyword to a destructor?
a ) No
70. What is the access level of a internal variable?
a ) current assembly
Wednesday, June 10, 2009
C# InterviewQuestions- Part 6
---------------------------
51. What are the types of strings?
a ) 2 types
1. mutable strings
2. immutable strings
52. Is a string is a reference type or value type?
a ) A string is reference type
53. What do you mean by mutable and immutable ?
a ) Mutable means we can alter the characters contained in them.
Immutable means that we can not alter the characters contained in them
54. What are String and StringBuilder classes?
a ) String class is an immutable class and
StringBuilder class is an mutable class
55. Tell me some methods present in StringBuilder class?
a ) They are
Append(),
Insert(),
Remove(),
Replace(),
appendFormat()
56. What is the namespace of StringBuilder class?
a ) System.Text
57. Tell me some methods present in String class?
a ) They are
Copy(),
Equals(),
ConCat(),
Compare(),
Trim(),
Substring(),
58. Can you store multiple data types in System.Array ?
a ) No.
59. What is the class from which an array is created(derived) automatically in c#
a ) System.Array
60. Some common methods of System.Array class?
a ) Clear(), CpoyTo(), GetValue(), Sort(), Reverse() etc.
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?
Monday, March 2, 2009
C# InterviewQuestions- Part 4
---------------------------
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.
Monday, February 23, 2009
C# InterviewQuestions- Part 3
--------------------------
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)