98-361 · Question #164
98-361 Question #164: Real Exam Question with Answer & Explanation
The correct answer is A. Provide a public function that assigns a value to the data member.. In this example (see below), the Employee class contains two private data members, name and salary. As private members, they cannot be accessed except by member methods. Public methods named GetName and Salary are added to allow controlled access to the private members. The name
Question
Options
- AProvide a public function that assigns a value to the data member.
- BCreate global variables in the class.
- CAssign a value directly to the data member.
- DProvide a private function that assigns a value to the data member.
Explanation
In this example (see below), the Employee class contains two private data members, name and salary. As private members, they cannot be accessed except by member methods. Public methods named GetName and Salary are added to allow controlled access to the private members. The name member is accessed by way of a public method, and the salary member is accessed by way of a public read-only property. Note: The private keyword is a member access modifier. Private access is the least permissive access level. Private members are accessible only within the body of the class or the struct in which they are declared private string name = "FirstName, LastName"; private double salary = 100.0; public string GetName() public double Salary get { return salary; }
Community Discussion
No community discussion yet for this question.