Engineering Science 1036A/B Lecture 26: Class and Objects: Accessor/Mutator

16 views4 pages
Access Privileges in a Class
Public data or function members can be accessed from the main() function
(driver function) directly using member access operator
Private data or function members can not be accessed directly from the main
function but can be accessed indirectly by any public member functions of the
same class
Compiler error will be generated if we attempt to access private members
using dot operator
Can be listed in any order in a class
Can appear multiple times in a class declaration
If not specified, the default is private
Example with private data members
Accessor/Mutator Functions
To access private data members from the main function indirectly, the class
declaration contains two types of public functions known as accessor and
mutator functions
Get-functions is referred to as a getter (accessor)
return Type getPropertyName();
§
Set-function is referred to as a setter (mutator)
void setPropertyName(dataType propertyValue);
§
Accessor/Mutator
Unlock document

This preview shows page 1 of the document.
Unlock all 4 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents