300+ [LATEST] C# Oops Interview Questions and Answers

Q1. What Is ‘this’ Pointer?

‘this’ pointer refers to the current object of a class.

Q2. Difference Between Const, Readonly And Static Readonly In C# ?

  • Constant variables are declared and initialized at compile time. The value can’t be changed after words.
  • Readonly variables will be initialized only from the non-static constructor of the same class.
  • Static Readonly variables will be initialized only from the static constructor of the same class.

Q3. Is It Possible For A Class To Inherit The Constructor Of Its Base Class?

No. A class cannot inherit the constructor of its base class.

Q4. Is It Possible To Execute Two Catch Blocks?

No. Whenever, an exception occurs in your program, the correct catch block is executed and the control goes to the finally block.

Q5. You Declare An Overridden Method To Be Static If The Original Method Is Not Static?

No. Two virtual methods must have the same signature.

Q6. What’s The Difference Between The ‘ref’ And ‘out’ Keywords?

An argument passed as “ref” must be initialized before passing to the method whereas “out” parameter needs not to be initialized before passing to a method, and it will be initialized inside the method.

Q7. Can You Inherit Private Members Of A Class?

No, we cannot inherit private members of a class because private members are accessible only to that class and not outside that class.

Q8. Can You Allow A Class To Be Inherited, But Prevent A Method From Being Overridden In C#?

Yes. By Declaring the class public and making the method sealed.

Q9. Can You Prevent A Class From Overriding?

Yes. You can prevent a class from overriding in C# by using the sealed keyword; and in VB by using NotInheritable keyword.

Q10. Why To Use “using” Statement In C#?

The using block is used to obtain a resource and use it and then automatically dispose off when the execution of block completed.

Q11. Can ‘this’ Be Used Within A Static Method?

No.