Coding - practical 9 Flashcards
What is the ‘class’ keyword used for?
- Defining a class
What follows the class keyword?
- The name of the class (should always start with capital letter)
What comes after the class keyword
{ and the Public keyword - used to define parts of our class that are visible to other parts of the program
What comes after the public keyword?
A brace should always follow the class name, and the class definition ends with a closing brace and semicolon.
What are member variables?
Member variables are like normal variables except they define some property about our class.
How do you create an instance of your class variable?
Add it under shared variables
What is the dot operator used for?
To set or access a class’s member variables
What are class methods?
Class methods are functions that live inside a class definition and normally act upon the state of the class in someway.
What does a class method have access to?
A class method has access to all of a classes member variables, without needing to use the dot operator.
How do you add a class method?
To add a class method simply define a function within the class’s definition, underneath the public label, and before the ending brace.
What is a class?
A class in C++ is a user defined type or data structure that has data and functions (also called methods)
What are the labels that that we use inside our class to define visibility of methods and members?
- Public: All other code can access the member variables and call the methods
- Private: Only the class itself can use the member variables or methods.