Saturday 27 July 2013

Simple Example of Constructor (B)

#include <iostream.h>
#include<conio.h>
class Line
{
   public:
      void setLength(double len);
      double getLength();
      Line();

   private:
      double length;
};
Line::Line()
{
    cout<<"Object is being created"<< endl;
}

void Line::setLength( double len )
{
    length = len;
}

double Line::getLength()
{
    return length;
}
void main( )
{
    clrscr();
    Line line;
    line.setLength(6.0);
    cout << "Length of line : " << line.getLength() <<endl;
    getch();
}

Here is the output :)


No comments:

Post a Comment