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.
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