Search This Blog

Sunday, July 3, 2011

Method Overriding

Example:-1



#include<iostream.h>
class Movie
{
public:
void start()
{
cout<<"Welcome"<<endl;
}
void interval()
{
cout<<"Interval - Have coffee of Rs. 5/-"<<endl;
}
void end()
{
cout<<"Thank you - come back again"<<endl;
}
};
class jungleBook:public Movie
{
public:
void reelone()
{
cout<<"Mowgli enters the jungle"<<endl;
}
void reeltwo()
{
cout<<"Bagheera saves mowgli"<<endl;
}
};
void main()
{
jungleBook jb;
jb.start();
jb.reelone();
jb.interval();
jb.reeltwo();
jb.end();
}
-----------------------------------
Example:-2



#include<iostream.h>
class Movie
{
public:
void start()
{
cout<<"Welcome"<<endl;
}
void interval()
{
cout<<"Interval - Have coffee for Rs. 5/-"<<endl;
}
void end()
{
cout<<"Thank you - come again"<<endl;
}
};
class JungleBook:public Movie
{
public:
void reelone()
{
cout<<"Mowgli enters the jungle"<<endl;
}
void reeltwo()
{
cout<<"Bagheera saves mowgli"<<endl;
}
void interval()  //Interval method Overrided
{
cout<<"Interval- Have Pepsi for Rs.10/-"<<endl;
}
};
void main()
{
JungleBook jb;
jb.start();
jb.reelone();
jb.interval();
jb.reeltwo();
jb.end();
}
---------------------------------------------------
Example:-3



#include<iostream.h>
class Movie
{
public:
void start()
{
cout<<"Welcome"<<endl;
}
void interval()
{
cout<<"Interval- Have coffee for Rs.5/-"<<endl;
}
void end()
{
cout<<"Thank you come again"<<endl;
}
};
class JungleBook:public Movie
{
public:
void reelone()
{
cout<<"Mowgli enters the jungle"<<endl;
}
void reeltwo()
{
cout<<"Bagheera saves the mowgli"<<endl;
}
void interval()
{
interval();
cout<<"and have Pepsi for Rs.10/-"<<endl;
}
};
void main()
{
JungleBook jb;
jb.start();
jb.reelone();
jb.interval();
jb.reeltwo();
jb.end();
}
-------------------------------------------------------
Example:-4


#include<iostream.h>
class Movie
{
public:
void start()
{
cout<<"Welcome"<<endl;
}
void interval()
{
cout<<"Interval- Have coffee for Rs.5/-"<<endl;
}
void end()
{
cout<<"Thank you come again"<<endl;
}
};
class JungleBook:public Movie
{
public:
void reelone()
{
cout<<"Mowgli enters the jungle"<<endl;
}
void reeltwo()
{
cout<<"Bagheera saves the mowgli"<<endl;
}
void interval()
{
Movie::interval();
cout<<"and have Pepsi for Rs.10/-"<<endl;
}
};
void main()
{
JungleBook jb;
jb.start();
jb.reelone();
jb.interval();
jb.reeltwo();
jb.end();
}


-------------------------------------------------------------------------------

No comments:

Post a Comment

Plz go for it..........