Most Important Frequently Asked C# Oops Interview Questions
Interview Quesions on C# Oops
-
Question 1. Can You Allow A Class To Be Inherited, But Prevent A Method From Being Overridden In C#?
Answer :
Yes. By Declaring the class public and making the method sealed.
-
Question 2. You Declare An Overridden Method To Be Static If The Original Method Is Not Static?
Answer :
No. Two virtual methods must have the same signature.
C#. NET Interview Questions -
Question 3. Can You Inherit Private Members Of A Class?
Answer :
No, we cannot inherit private members of a class because private members are accessible only to that class and not outside that class.
-
Question 4. Is It Possible To Execute Two Catch Blocks?
Answer :
No. Whenever, an exception occurs in your program, the correct catch block is executed and the control goes to the finally block.
C#. NET Tutorial -
Question 5. Can You Prevent A Class From Overriding?
Answer :
Yes. You can prevent a class from overriding in C# by using the sealed keyword; and in VB by using NotInheritable keyword.
ASP.NET Interview Questions -
Question 6. What Is 'this' Pointer?
Answer :
'this' pointer refers to the current object of a class.
-
Question 7. Can 'this' Be Used Within A Static Method?
Answer :
No.
ASP.NET Tutorial Microsoft Entity Framework Interview Questions -
Question 8. Is It Possible For A Class To Inherit The Constructor Of Its Base Class?
Answer :
No. A class cannot inherit the constructor of its base class.
-
Question 9. What's The Difference Between The 'ref' And 'out' Keywords?
Answer :
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.
LINQ Interview Questions -
Question 10. Difference Between Const, Readonly And Static Readonly In C# ?
Answer :
- 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.
Microsoft Entity Framework Tutorial -
Question 11. What Is The Difference Between “dispose” And “finalize” Variables In C#?
Answer :
Dispose() Method
- Dispose method will be used to free unmanaged resources like files, database connection etc.
- To clear unmanaged resources we need to write code manually to raise dispose() method.
- This Dispose() method belongs to IDisposable interface.
- If we need to implement this method for any custom classes we need to inherit the class from IDisposable interface.
Finalize() Method
- Finalize method also free unmanaged resources like database connections, files etc.
- It is automatically raised by garbage collection mechanism whenever the object goes out of scope.
- This method belongs to object class.
- We need to implement this method whenever we have unmanaged resources in our code and make sure these resources will be freed when garbage collection process done.
Framework7 Interview Questions -
Question 12. Why To Use "using" Statement In C#?
Answer :
The using block is used to obtain a resource and use it and then automatically dispose off when the execution of block completed.
C#. NET Interview Questions
Topic: C# Oops Interview Questions
Interview Quesions on C# Oops
No comments:
Post a Comment