Object Oriented Programming With C++

20 Questions | Total Attempts: 114

SettingsSettingsSettings
Object Oriented Programming With C++ - Quiz

.


Questions and Answers
  • 1. 
    What is the final value of x when the code int x; for(x=0; x<10; x++) {} is run?
    • A. 

      10

    • B. 

      9

    • C. 

      0

    • D. 

      1

  • 2. 
    In an assignment statement a=b Which of the following statement is true?
    • A. 

      The variable a and the variable b are equal.

    • B. 

      The value of b is assigned to variable a but the later changes on variable b will not effect the value of variable a

    • C. 

      The value of b is assigned to variable a and the later changes on variable b will effect the value of variable a

    • D. 

      The value of variable a is assigned to variable b and the value of variable b is assigned to variable a.

  • 3. 
    Which of the following type of class allows only one object of it to be created?
    • A. 

      Virtual class

    • B. 

      Abstract class

    • C. 

      Singleton class

    • D. 

      Friend class

  • 4. 
    Which of the following statements is correct?
    • A. 

      Base class pointer cannot point to derived class.

    • B. 

      Derived class pointer cannot point to base class.

    • C. 

      Pointer to derived class cannot be created.

    • D. 

      Pointer to base class cannot be created.

  • 5. 
    Which of the following provides a reuse mechanism?
    • A. 

      Abstraction

    • B. 

      Inheritance

    • C. 

      Dynamic binding

    • D. 

      Encapsulation

  • 6. 
    What is the output of the following code char symbol[3]={‘a’,‘b’,‘c’}; for (int index=0; index<3; index++) cout << symbol [index];
    • A. 

      A b c

    • B. 

      “abc”

    • C. 

      Abc

    • D. 

      ‘abc’

  • 7. 
    The process of building new classes from existing one is called _________.
  • 8. 
    If a class C is derived from class B, which is derived from class A, all through public inheritance, then a class C member function can access
    • A. 

      Protected and public data only in C and B.

    • B. 

      Protected and public data only in C.

    • C. 

      Private data in A and B.

    • D. 

      Protected data in A and B.

  • 9. 
    To perform stream I/O with disk files in C++, you should
    • A. 

      Open and close files as in procedural languages.

    • B. 

      Use classes derived from ios

    • C. 

      Use C language library functions to read and write data.

    • D. 

      Include the IOSTREAM.H header file.

  • 10. 
    Overloading the function operator
    • A. 

      Requires a class with an overloaded operator.

    • B. 

      Requires a class with an overloaded [ ] operator.

    • C. 

      Allows you to create objects that act syntactically like functions.

    • D. 

      Usually make use of a constructor that takes arguments.

  • 11. 
    RunTime Polymorphism is achieved by ______
  • 12. 
    In C++, dynamic memory allocation is accomplished with the operator ____
  • 13. 
    What will be the output of the following C++ code? #include<iostream> using namespace std;   class Test { protected: int x; public: Test (int i):x(i) { } void fun() const { cout << "fun() const " << endl; } void fun() { cout << "fun() " << endl; } };   int main() { Test t1 (10); const Test t2 (20); t1.fun(); t2.fun(); return 0; }
    • A. 

      fun() const fun()

    • B. 

      fun() fun() const

    • C. 

      fun() fun()

    • D. 

      fun() const fun() const

  • 14. 
    What will be the output of the following C++ code? #include <iostream> using namespace std;   int fun(int=0, int = 0);   int main() { cout << fun(5); return 0; } int fun(int x, int y) { return (x+y); }
    • A. 

      -5

    • B. 

      0

    • C. 

      10

    • D. 

      5

  • 15. 
    What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { static int a; public: void show() { a++; cout<<"a: "<<a<<endl; } };   int A::a = 5;   int main(int argc, char const *argv[]) { A a; return 0; }
    • A. 

      Segmentation fault

    • B. 

      Error as a private member a is referenced outside the class

    • C. 

       No output

    • D. 

      Program compiles successfully but gives run-time error

  • 16. 
    What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A{ int a; A(){ a = 5; }   public: void assign(int i){ a = i; } int return_value(){ return a; } }; int main(int argc, char const *argv[]) { A obj; obj.assign(10); cout<<obj.return_value(); }
    • A. 

      Error

    • B. 

      5

    • C. 

      10

    • D. 

      Segmentation fault

  • 17. 
    What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class Box { int capacity; public: Box(int cap){ capacity = cap; }   friend void show(); };   void show() { Box b(10); cout<<"Value of capacity is: "<<b.capacity<<endl; }   int main(int argc, char const *argv[]) { show(); return 0; }
    • A. 

      Value of capacity is: 10

    • B. 

      Value of capacity is: 100

    • C. 

      Error

    • D. 

      Segmentation fault

  • 18. 
    How the template class is different from the normal class?
    • A. 

      Template class generate objects of classes based on the template type

    • B. 

       Template class saves system memory

    • C. 

      Template class helps in making genetic classes

    • D. 

       All of the mentioned

  • 19. 
    Which of the following accesses a variable in structure *b?
    • A. 

      B->var;

    • B. 

      B.var;

    • C. 

      B-var;

    • D. 

      B>var;

  • 20. 
     The operator used for dereferencing or indirection is ____
    • A. 

      ->

    • B. 

      –>>

    • C. 

      *

    • D. 

      &

Back to Top Back to top
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.