Menu BAR

FEEL FREE TO ASK ANY PROGRAM and please mention any error if you find it

5 Aug 2014

C++ CLASS EXAMPLE

Program to create a simple class in C++

#include<iostream.h>
class simple
{
  private:
  void you()
  {
    cout<<"Hi, i am private, you cannot access in main.";
   }
  public:
  void hello()
  {
     cout<<"Welcome to hello function.\n";
   }
   void world()
  {
    cout<<"You are now in world function.";
   }
};
void main()
{
  simple obj;  //creating object of class simple
  cout<<"Welcome to main function.\n";
  obj.hello();  //accessing the function hello using the object obj of class simple
  obj.world();
  //object.you();  //this will give error because the function is private
  getch();
}

==OUTPUT==
Welcome to main function.
Welcome to hello function.
You are now in world function.

2 comments:

  1. Thanks !
    You can visit this also
    http://computerarea96.blogspot.in/

    ReplyDelete
  2. Thanks !
    You can visit this also
    http://computerarea96.blogspot.in/

    ReplyDelete