Using the Public and Private Words to Hide Parts of Your Class - C++ Class

C++ examples for Class:Member Access

Description

Using the Public and Private Words to Hide Parts of Your Class

Demo Code

#include <iostream>

using namespace std;

class Oven//  w  ww.  j  a  v  a2  s. c om
{
private:
    void turnOn();
    void turnOff();

public:
    void cook(int val);
};

void Oven::turnOn()
{
    cout << "ON! Be careful!" << endl;
}

void Oven::turnOff()
{
    cout << "Off. Relax!" << endl;
}

void Oven::cook(int val)
{
    turnOn();
    cout << "Baking!" << endl;
    turnOff();
}

int main()
{
    Oven fred;
    fred.cook(875);
    return 0;

}

Result


Related Tutorials