Wednesday, 21 April 2021

Inheritance in C++ Qus - 1

 #include<conio.h>

#include<iostream.h>

class A

{

private:

int a;

protected:

int b;

public:

int c;


};

class B:public A

{

public:

int d;


};

int main()

{

clrscr();

B ob;

cout<<sizeof(ob)<<endl;           //6 bytes super, 2 bytes sub

ob.a=10;   //not inherit private in B

ob.b=20;   //private in B

ob.c=30;   //private in B

ob.d=40;  //public in B

getch();

return 0;

}

No comments:

Post a Comment