Encapsulation is another fundamental concept in OOP where the details of a class, that is, the attributes and methods, can be visible or not visible outside the object. With encapsulation, a developer is providing guidance on how a class should be used as well as helping to prevent a class from being handled incorrectly. For example, let's say we wanted to only allow adding PetAnimal objects by using the AddPet(PetAnimal) method. We would do this by having the PetOwner class's AddPet(PetAnimal) method available while having the Pets attribute restricted to anything outside the PetAnimal class. In C#, this is possible by making the Pets attribute private. One reason for doing this would be if additional logic was required whenever a PetAnimal class was added, such as logging or validating that the PetOwner class could have a pet.
C# supports different levels...