Method Overriding: -
the method having
same name, same signature but in different class (inherited class).
E.g.:
#include<iostream.h>
#include<conio.h>
Class a
{
Public:
Void display()
{
Cout<<”Base
class”;
}
};
Class b: public a
{
Public:
Void display()
{
Cout<<”child
class”;
}
};
Void main()
{
Class();
B
z;
z.display();
getch();
}
Method Overloading: -
The method having Same
name, different signature in single class.
E.g.:
//Method Overloading
#include<iostream.h>
#include<conio.h>
class student
{
public:
void show() //Without
Parameter Method
{
cout<<"BCA
3rd Semester Student Details"<<endl;
}
void show(int x) //With integer Parmeter Method
{
cout<<"
Student Rollno: "<<x<<endl;
}
void show(char name[30]) //Character Parameter Method
{
cout<<" Student Name :
"<<name<<endl;
}
void show(float x,float
y) //With Float Parameter Method
{
cout<<" OOPS & C++ Marks :
"<<x<<endl;
cout<<" Practical Marks : "<<y<<endl;
}
};
{
clrscr();
student s;
s.show(); //Without
Parameter Calling
s.show(801); //With
Integer Parameter Call
s.show("Online Study");
//With Character Parameter Call
s.show(75.5f,78.5f); //With Float Parameter Call
getch();
}
Inheritance : 1. Public inheritance
Private inheritance
Protected inheritance
Normally we use
public :
Public ----> Base class Child class
Private -------
Public Public
Protected Protected
Private ----> Public Private
Protected Private
Protected ----> Public Protected
Protected Protected
In multiple
inheritance: -
There will we
conflict.
How to resolve that
-> ::
#include<iostream.h>
#include<conio.h>
Class a
{
Public:
Void display()
{
Cout<<”jai
hind ! Base”;
}
};
Class b
{
Public:
Void display()
{
Class<<”online
study”;
}
};
Class c : public
a,public b
{
Public:
Void display()
{
Cout<<”welcome
to online study”;
}
};
Void main()
{
Clrscr();
C
z;
z.display();
z.b::display();
getch();
}
No comments:
Post a Comment