Interview Quesions involving class and method modifiers.
1. What are the features of an abstract class?
Answer: It cannot be instantiated.It can contain abstrast methods and accessors.
2. When an non-abstract class derives from an abstract class with abstract methods or accessors what must it do?
Answer: It must provide implementations for all abstract methods and accessors.
3. What is an abstract method?
Answer: Implicitly it is a virtual method.Permitted only in abstract classes.It has no body.
4. Why are abstract methods not permitted in non-abstract classes?
Answer: Abstract methods have no implementation, which would be required in a concrete class.
5. When a field or local variable is marked const what does it change?
Answer: The value cannot change. It can only be initialized at declaration.
6. How is override used?
Answer: It is used to modify a method, property or indexer to change the implementation.
7. When a field is marked readonly what does it change?
Answer: The value can only be set in the constructor during initialization.
8. In terms of runtime and compile time, compare const and readonly.
Answer. const is compile time and readonly is runtime.
9. What is a sealed class?
Answer: The class cannot be derived by another class.
10. How does static change fields and methods?
Answer: They become global and belong to the type instead of the instance.
11. What is a virtual method?Answer: It is a method that implementation can be changed in a derived class by using the override keyword.
12. Why is modifiying a class with both abstract and sealed an error?
Answer: An abstract class cannot be instantiated
No comments:
Post a Comment