Sep

08

//——————————– PROGRAM -1 ————————————-

#include<iostream.h>
class A{
public:
void af1(){
cout<<“af1() called from B”;
}
};
/*class B:A{
};*/
/*class B:protected A{
};*/
class B:public A{
};
void main(){
B b1;
b1.af1();
}

//———————————————– PROGARM – 2—————————————

#include<iostream.h>
class A{
protected:
void af1(){
cout<<“af1() called from A”<<endl;
}
};
class B:public A{
public:
void bf1(){
af1();
cout<<“bf1() called from B”<<endl;
}
};
void main(){
B b1;
//b1.A::af1();
b1.bf1();
}

//———————————————– PROGRAM -3 ————————————-

#include<iostream.h>
class A{
protected:
void af1(){
cout<<“af1() called from A”<<endl;
}
};
class B:public A{
public:
void af1(){
A::af1();
cout<<“af1() called from B”<<endl;
}
};
void main(){
B b1;
//b1.A::af1();
b1.af1();
}

//—————————————– PROGRAM – 4—————————————————–

#include<iostream.h>
class A{
public:
/*A(){
cout<<“A() cons called”<<endl;
}*/
};
class B:public A{
public:
B(){
cout<<“B() cons called”<<endl;
}
};
void main(){
B b1;
}

//—————————————- PROGRAM -5 —————————————

#include<iostream.h>
class A{
public:
A(){
cout<<“A()”<<endl;
}
A(int n){
cout<<“A(int n) cons called”<<endl;
}
};
class B:public A{
public:
B(){
A(30);
cout<<“B() cons called”<<endl;
}
};
void main(){
B b1;
}


Leave a Reply