Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     

.NET OOPS interview questions: - How can we implement encapsulation and inheritance in .NET?

This question can be asked in different way to confuse developer as “What are the different access modifiers in .NET?”. In either condition answer would going to be as follows: -

Implementing encapsulation: -

Encapsulation can be achieved or implement by using the below 5 access modifiers.
  • Private: - Only members of class have access to the variables.
  • Protected: - All members in current class and in derived classes can access the variables.
  • Friend (internal in C#): - Only members in current project have access to the elements.
  • Protected friend (protected internal in C#): - All members in current project and all members in derived class can access the variables.
  • Public: - All members have access in all classes and projects.

Implementing Inheritance in .NET: -

Inheritance is implemented by using the “:” symbol.

Below is a simple code snippet where we have “Customer” class which is the parent class. We have then created a child class called as “CustomerDiscount” which inherits all the properties and adds a “Discount” property.

class Customer


public string customerName;

public string customerCode;



class CustomerDiscount : Customer


public double Discount;


Also see another .NET OOPS interview questions video on difference between Abstraction and Encapsulation: -

Helpful Website Url
Share this article   |    Print    |    Article read by 2520 times
Shivprasad koirala Koirala
I am a Microsoft MVP for ASP/ASP.NET and currently a CEO of a small E-learning company in India. We are very much active in making training videos , writing books and corporate trainings. Do visit my site for .NET, C# , design pattern , WCF , Silverlight , LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server training and Interview questions and answers
Related Articles:
Related Interview Questions: