Choose the correct statements from the following:
A. | In a struct, the access control is public by default. |
B. | In a class, the access control is private by default. |
C. | In a class, the access control is public by default. |
D. | Both (a) & (b) |
Option: D Explanation : Click on Discuss to view users comments. |
The fields in a class, of a C++ program are by default
A. | protected |
B. | public |
C. | private |
D. | none of the above |
Option: C Explanation : Click on Discuss to view users comments. |
Class A
{
int i1;
protected :
int i2;
public :
int i3;
}
class B : public A
{
public :
int i4;
};
class C :B
{
};
The variable i2 is accessible
A. | to a public function in class A |
B. | to a public function in cIa s s B |
C. | to a public function in class C |
D. | from the main function |
Option: C Explanation : Click on Discuss to view users comments. |
Class A
{
int i1;
protected :
int i2;
public :
int i3;
}
class B : public A
{
public :
int i4;
};
class C :B
{
};
Which varilible(s) is/are accessible from the main function?
A. | i1 |
B. | i 2 |
C. | i 3 |
D. | None of the above |
Option: D Explanation : Click on Discuss to view users comments. reetikaa said: (10:03pm on Thursday 24th September 2015)
i think it shuld be i3 as it is accessible to all since it is public
Muhammad Ali said: (12:34am on Wednesday 28th February 2018)
i3 will be accessible from the main function as it is public
|
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 |
Option: 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. Click on Discuss to view users comments. |
Syllabus covered in this section is-
This Section covers OOPS Questions Answers .These questions can be used for the preparation of various competitive and academic exams like
Who can benefit
Various Search Terms Used For This Section Are