101. What is the difference between Shadowing and Overriding?
Overriding redefines only the implementation while shadowing redefines the whole element.
In overriding derived classes can refer the parent class element by using “ME” keyword, but in shadowing you can access it by “MYBASE”.
102. Can events have access modifiers?
Yes, you can have access modifiers in events. You can have events with the protected keyword, which will be accessible only to inherited classes. You can have private events only for objects in that class.
103. Why is the virtual keyword used in code?
The Virtual keyword is used in code to define methods and the properties that can be overridden in derived classes.
104. What are constructors and destructors?
Constructors and destructors are special methods.
Constructors and destructors are special methods of every class.
Each class has its own constructor and destructor and are called automatically when the instance of a class is created or destroyed.
The constructor initializes all class members whenever you access the class and the destructor destroys them when the objects are not required anymore.
105. How can we suppress a finalize method?
106. Does C# support a variable number of arguments?
Yes, using the params keyword.
The arguments are specified as a list of arguments of a specific type, e.g., int. For ultimate flexibility, the type can be object.
The standard example of a method which uses this approach is System.console.writeLine().
107.Which method will you call to start a thread?
Start Method is used to start a thread.
108. What is Generic?
Generic help us to create flexible strong type collection.
Generic basically seperate the logic from the datatype in order maintain better reusability, better maintainability etc.
109. What are the different types of polymorphism?
There are two types of polymorphism. They are:
- Compile time Polymorphism
- Run time Polymorphism
110. What is the difference between compile time polymorphism and run time polymorphism?
Compile time Polymorphism
Compile time Polymorphism also known as method overloading.
Method overloading means having two or more methods with the same name but with different signatures.
Run time Polymorphism
Run time Polymorphism also known as method overriding.
Method overriding means having two or more methods with the same name , same signature but with different implementation.