Nested Class In C++
A nested class is a class that is declared in
another class. The nested class is also a member variable of the enclosing
class and has the same access rights as the other members. However, the member
functions of the enclosing class have no special access to the members of a
nested class.
Program:
#include<iostream.h>
#include<conio.h>
class emp;
class A
{
public:
class
B
{
private:
int
num;
public:
void
get(int n)
{
num=n;
}
void
put()
{
cout<<”the
number is “<<endl;
}
};
};
void
main()
{
cout<<”nested
class in c++”<<endl;
A::B
obj;
obj.get(9);
obj.put();
getch();
}
Output:
Nested
class in c++
The
number is 9
No comments:
Post a Comment