C++ Oop
C++ Oop
C++
By Eng.Adulahi M. Adan
http://www.mahergelle.com
Chapter Three: -
Loops, Arrays and
Functions
C++ OOP
Contents
Example explained
The class keyword is used to create a class called MyClass.
The public keyword is an access specifier, which specifies
that members (attributes and methods) of the class are
accessible from outside the class.
Inside the class, there is an integer variable myNum and
a string variable myString. When variables are declared
within a class, they are called attributes.
At last, end the class definition with a semicolon ;.
Create an Object
Contents
Inside Example
class MyClass { // The class
public: // Access specifier
void myMethod() { // Method/function defined inside the class
cout << "Hello World!";
}
};
int main() {
MyClass myObj; // Create an object of MyClass
myObj.myMethod(); // Call the method
return 0;
}
C++ Class Methods
Contents