Access Specifier
_ | Desc | Defaults |
---|---|---|
Public | Accessable even outside the namespace | interface, enum |
Private | Only on same class | method, constructor |
Protected | Accessed in child class and helps inheritance | |
Internal | Within application | top levelclass, delegate, interface |
Protected Internal | Same assembly, or any derived class different assembly. (protected or internal) |
Can you declare a private class in a namespace?
The classes in a namespace are internal, by default.
However, you can explicitly declare them as public
and not as private, protected, or protected internal
. The nested classes can be declared as private,protected, or protected internal
.
Why use Get Set Modifier
The get set accessor or modifier mostly used for storing and retrieving value from the private field. The get must return a value of property type where as set returns void.
In simple word, the get method used for retrieving value from private field whereas set method used for storing value in private variables.
What is Static Constructor
When we declared static constructor it will be invoked only once for any number of instances. Static constructor is used to initialize static fields of the class and to write the code that needs to be executed only once.
Can a private virtual method be overridden?
No, CLR with not allow private in virtual method
What is enum
An enumeration is a set of named integer constants. An enumerated type is declared using the enum keyword.
enum Importance {
None,
Trivial,
Regular,
Important,
Critical
};
Some True Statement
- Override method is used to provide implementation of abstract method
- We cannot use static or virtual modifiers to declare abstract methods.
- Declaration of abstract methods is limited only to the abstract class
- Abstract classes can be inherited in derived classes
- Abstract classes can not be instantiated
- Abstract classes can contain both definition and body
- all the members, properties, methods defined inside it must be declared static.
- static class constructors must be private
- members, properties and methods are accessed with static class name
- sealed classes can be instantiated
- sealed keyword is used for declaring class
- sealed classes are used to restrict the inheritace feature of oop
- sealed classes are primarily used to prevent derivation