CPP

CPP

Access Control has 9 Questions
How many access specifiers are there in c++?

1
2
3
4
What of the following describes protected access specifier?

The variable is visible only outside inside the block
The variable is visible everywhere
The variable is visible to its block and to it's derived class
None of the mentioned
To which of the following access aspecifiers are applicable?

Member data
Functions
Both a & b
None of the mentioned
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     class student
  4.     {
  5.         public:
  6.         int rno , m1 , m2 ;
  7.         protected:
  8.         void get()
  9.         {
  10.             rno = 15, m1 = 10, m2 = 10;
  11.         }
  12.     };
  13.     class sports
  14.     {
  15.         public:
  16.         int sm;
  17.         void getsm()
  18.         {
  19.             sm = 10;
  20.         }
  21.     };
  22.     class statement : public student, public sports
  23.     {
  24.         int tot, avg;
  25.         public:
  26.         void display()
  27.         {
  28.             tot = (m1 + m2 + sm);
  29.             avg = tot / 3;
  30.             cout << tot;
  31.             cout << avg;
  32.         }
  33.         void setObject()
  34.         {
  35.             get();
  36.         }
  37.     };
  38.     int main()
  39.     {
  40.         statement obj;
  41.         obj.setObject();
  42.         obj.getsm();
  43.         obj.display();
  44.     }

3010
1010
2100
Error
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     struct A 
  4.     {
  5.         private:
  6.         int i, j, k;
  7.         public:
  8.         int f();
  9.         void g();
  10.     };
  11.     int A :: f() 
  12.     {
  13.         return i + j + k;
  14.     }
  15.     void A :: g() 
  16.     {
  17.         i = j = k = 0;
  18.     }
  19.     class B 
  20.     {
  21.         int i, j, k;
  22.         public:
  23.         int f();
  24.         void g();
  25.     };
  26.     int B :: f() 
  27.     {
  28.         return i + j + k; 
  29.     }
  30.     void B :: g() 
  31.     {
  32.         i = j = k = 0;
  33.     }
  34.     int main() 
  35.     {
  36.         A a;
  37.         B b;
  38.         a.f(); 
  39.         a.g();
  40.         b.f(); 
  41.         b.g();
  42.         cout << "Identical results would be produced";
  43.     }

50
Identical results would be produced
Error
Runtime error
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     struct X;
  4.     struct Y 
  5.     {
  6.         void f(X*);
  7.     };
  8.     struct X 
  9.     {
  10.         private:
  11.         int i;
  12.         public:
  13.         void initialize(); 
  14.         friend void g(X* , int);
  15.         friend void Y :: f(X*);
  16.         friend struct Z;
  17.         friend void h();
  18.     };
  19.     void X :: initialize() 
  20.     {
  21.         i = 0;
  22.     }
  23.     void g(X* x, int i) 
  24.     {
  25.         x -> i = i;
  26.     }
  27.     void Y :: f(X * x) 
  28.     {
  29.         x -> i = 47;
  30.         cout << x->i;
  31.     }
  32.     struct Z 
  33.     {
  34.         private:
  35.         int j;
  36.         public:
  37.         void initialize();
  38.         void g(X* x);
  39.     };
  40.     void Z::initialize() 
  41.     {
  42.         j = 99;
  43.     }
  44.     void Z::g(X* x) 
  45.     {
  46.         x -> i += j;
  47.     }
  48.     void h() 
  49.     {
  50.         X x;
  51.         x.i = 100;
  52.         cout << x.i;
  53.     }
  54.     int main() 
  55.     {
  56.         X x;
  57.         Z z;
  58.         z.g(&x);
  59.         cout << "Data accessed";
  60.     }

99
47
Data accessed
None of the mentioned
What is the default access level to a block of data?

Public
Protected
Private
None of the mentioned
What is the importance of mutable keyword?

It allows the data member to change within a const member function.
It will not allow the data member to change within a const member function.
It will copy the values of the variable.
None of the mentioned
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     class Cat
  4.     {
  5.         public:
  6.         int age;
  7.         int weight;
  8.     };
  9.     int main()
  10.     {
  11.         Cat f;
  12.         f.age = 56;
  13.         cout << "Gates is " ;
  14.         cout << f.age << " years old.\n";
  15.     }

Gates is
Gates is 56 years old
Error
None of the mentioned