Classes C++ MCQ

Errorlogger
0
1. What does your class can hold?
a) data
b) functions
c) both a & b
d) none of the mentioned

Answer:c


2. How many specifiers are present in access specifiers in class?
a) 1
b) 2
c) 3
d) 4

Answer:c


3. Which is used to define the member of a class externally?
a) :
b) ::
c) #
d) none of the mentioned

Answer:b


4. Which other keywords are also used to declare the class other than class?
a) struct
b) union
c) object
d) both a & b

Answer:d


5. What is the output of this program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     class rect
  4.     {
  5.         int x, y;
  6.         public:
  7.         void val (int, int);
  8.         int area ()
  9.         {
  10.             return (x * y);
  11.         }
  12.     };
  13.     void rect::val (int a, int b)
  14.     {
  15.         x = a;
  16.         y = b;
  17.     }
  18.     int main ()
  19.     {
  20.         rect rect;
  21.         rect.val (3, 4);
  22.         cout << "rect area: " << rect.area();
  23.         return 0;
  24.     }
a) rect area:12
b) rect area: 12
c) rect area:24
d) none of the mentioned

Answer:b


6. What is the output of this program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     class CDummy
  4.     {
  5.         public:
  6.         int isitme (CDummy& param);
  7.     };
  8.     int CDummy::isitme (CDummy& param)
  9.     {
  10.         if (&param == this)
  11.             return true;
  12.         else
  13.             return false;
  14.     }
  15.     int main ()
  16.     {
  17.         CDummy a;
  18.         CDummy *b = &a;
  19.         if (b->isitme(a)) {
  20.             cout << "execute";
  21.         }
  22.         else
  23.         {
  24.             cout<<"not execute";
  25.         }
  26.         return 0;
  27.     }
a) execute
b) not execute
c) none of the mentioned
d) both a & b

Answer:a


7. Which of the following is a valid class declaration?
a) class A { int x; };
b) class B { }
c) public class A { }
d) object A { int x; };

Answer:a


8. The fields in the class in c++ program are by default
a) protected
b) private
c) public
d) none of the mentioned

Answer:b


9. Constructors are used to
a) initalize the objects
b) construct the data members
c) both a & b
d) none of the mentioned

Answer:a


10. When struct is used instead of the keyword class means, what will happen in the program?
a) access is public by default
b) access is private by default
c) access is protected by default
d) none of the mentioned

Answer:a
Tags

Post a Comment

0Comments

Post a Comment (0)

#buttons=(Accept !) #days=(30)

Our website uses cookies to enhance your experience. Check Now
Accept !