Sunday, March 17, 2013

Constructor

#include<iostream>
using namespace std;
class Student{
                 int num;
                 public:
                 Student()
                 {
                     num=0;
                 }
                 Student(int n)
                 {
                     num=n;
                 }
                 void display();
             };
int main()
{
    Student a,a1(35),a2(45);
    a.display();
    a1.display();
    a2.display();
    return 0;
}
void Student::display()
{
    cout<<num<<"\n";
}

0 comments:

Post a Comment