C++ Class Access Specifiers Using the Public and Private to Hide Members

Description

C++ Class Access Specifiers Using the Public and Private to Hide Members

#include <iostream>

using namespace std;

class Oven/*from  w w w . ja  v  a 2s  .co  m*/
{
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;

}



PreviousNext

Related