The constructors in base classes can be no-argument constructors or multiple argument constructors.
No-argument Constructor
Sample Program
class A
{
public:
A()
{
cout<<”A”;
}
};
class B
{
public:
B()
{
cout<<”B”;
}
};
class C:public A, public B
{
public:
C()
{
cout<<”C”;
}
};
void main()
{
C obj;
}
the base class constructors are alw ays executed first, working from the first base class to the last and finally through the derived class constructor.
No comments:
Post a Comment