• +91 9723535972
  • info@interviewmaterial.com

CSharp Interview Questions and Answers

CSharp Interview Questions and Answers

Question - 31 : - Are private class-level variables inherited?

Answer - 31 : - Yes,but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are.

Question - 32 : - Describe the accessibility modifier protected internal.

Answer - 32 : - It’s available to derived classes and classes within the same Assembly (and naturally from the base class it’s declared in).

Question - 33 : - C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write?

Answer - 33 : - Two. Once you write at least one constructor, C# cancels the freebie constructor, and now you have to write one yourself, even if there’s no implementation in it

Question - 34 : - What’s the top .NET class that everything is derived from?

Answer - 34 : - System.Object

Question - 35 : - How’s method overriding different from overloading?

Answer - 35 : - When overriding, you change the method behavior for a derived class. Overloading simply involves having a method with the same name within the class.

Question - 36 : - What does the keyword virtual mean in the method definition?

Answer - 36 : - The method can be over-ridden.

Question - 37 : - Can you declare the override method static while the original method is non-static?

Answer - 37 : -  No, you can’t, the signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override.

Question - 38 : - Can you override private virtual methods?

Answer - 38 : - No, moreover, you cannot access private methods in inherited classes, have to be protected in the base class to allow any sort of access.

Question - 39 : - Can you prevent your class from being inherited and becoming a base class for some other classes?

Answer - 39 : - Yes, that’s what keyword sealed in the class definition is for. The developer trying to derive from your class

Question - 40 : - Can you allow class to be inherited, but prevent the method from being over-ridden?

Answer - 40 : - Yes, just leave the class public and make the method sealed.


NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners