Object Oriented Programming

1:

The following program
class abc;
class def
{
int i1 ;                        // statement 1
protected: int i2;   // statement 2
public: int i3;       //statement 3
friend abc;
} ;
class abc
{
public:
void main(def A)
{
cout << (A.i1=3);
cout <<  (A.i2=4);
cout << (A.i3=5);
}
} ;
void main( )
{
def x1 ;
abc x2 ;
x2.mn(x1);
}    

A.

will compile successfully if statement 1 is removed

B.

will compile successfully if statement 2 is removed

C.

will compile successfully if statement 3 is removed

D.

will run successfully and print 34 5

 

Answer : D

Explanation :

Since abc is a friend of def, it can access all its data, does not matter whether it is declared private, protected or public.

Write your comments here:


Report Error
 

Option: A

Explanation : Explanation will come here. Explanation will come here. Explanation will come here. Explanation will come here. Explanation will come here.