Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
4003CEM-Exam-Practise/Classes and Inheritance/class.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
25 lines (20 sloc)
700 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
/* | |
Classes now. The joy of them. | |
*/ | |
class MyClass { // defines a class for you | |
public: // adds a public identifier for all to access these | |
string stringer = "stringing"; // public string | |
int ten = 10; // public int | |
int get_nine() { // returns private int | |
return nine; | |
} | |
private: // adds a private identifer for only the class objects and functions to access | |
int nine = 9; // private int | |
}; | |
int main() { | |
MyClass myclass; // initialise class and make object: object -> myclass | |
cout << myclass.get_nine() << endl; // returns the value from the private int | |
return 0; // returns 0 | |
} |