207k views
0 votes
Public class Cheese { private string name; private int weight; private double price; private string features; }

What is the primary purpose of the provided C# class?
A) Data encryption
B) Object serialization
C) Data encapsulation
D) Inheritance

1 Answer

7 votes

Final answer:

The provided C# class serves the primary purpose of data encapsulation by bundling variables and methods into a single unit, restricting access to its private members.

Step-by-step explanation:

The primary purpose of the provided C# class is C) Data encapsulation. This class is a blueprint for creating objects that contain data and methods to protect access to that data. In object-oriented programming, encapsulation is one of the fundamental principles used to bundle the data (variables) and methods (functions) that work on the data into a single unit, or class. By labeling the data as private, the class restricts direct access from outside the class, thus enforcing encapsulation. Access to these private members can be controlled through public methods such as getters and setters.

User Kaloyan Stamatov
by
8.0k points