Difference between Abstraction and Encapsulation
Difference between Abstraction and Encapsulation
programming (OOP) that often get confused, but they serve different purposes.
Here’s a clear distinction between the two:
### Abstraction
```csharp
public abstract class Animal
{
public abstract void MakeSound();
}
```csharp
public interface IAnimal
{
void MakeSound();
}
### Encapsulation
```csharp
public class Person
{
private string name;
In this example:
- `name` is a private field and cannot be accessed directly from outside the
`Person` class.
- `Name` is a public property that provides controlled access to the private
`name` field.
- **Getters and Setters:** Methods that allow controlled access to the private
fields of a class.
### Summary