In the name of ALLAH, the most beneficient, the most merciful

Object Oriented Programming (CS304)

Multiple Choice Questions (MCQs)

Objective Questions

  1. In C++, which of the following keywords works only with constructors?

    1. const
    2. static
    3. explicit
    4. virtual
  2. In case of private inheritance, private members of base class will be ________ in derived class.

    1. private
    2. public
    3. protected
    4. hidden
  3. In resolution order compiler search firstly ________.

    1. Generic Template
    2. Partial Specialization
    3. Complete Specialization
    4. Ordinary function
  4. In polymorphism, messages can be interpreted in different ways depending upon the ________ class.

    1. base
    2. derived
    3. sender
    4. receiver
  5. What is a class?

    1. A class is a section of computer memory containing objects
    2. A class is a section of the hard disk reserved for object oriented programs
    3. A class is the part of an object that contains the variables
    4. A class is a description of a kind of object
  6. When derived class has user defined assignment operator.

    1. Compiler itself calls base class assignment operator.
    2. Compiler itself calls base class copy constructor.
    3. Compiler itself calls base class default constructor.
    4. Compiler does nothing.
  7. Which of the following is True about class?

    1. It is a mechanism in C++ to realize objects in a program.
    2. It is concrete implementation of objects in C++
    3. It is used to create new types in C++ according to our requirement
    4. All of the given
  8. In ________, Base class can't always be replaced by the derived class.

    1. Aggregation
    2. Inheritance
    3. Specialization
    4. Extension
  9. Generalization is ________ approach.

    1. Bottom-up
    2. Top-bottom
    3. Right-Left
    4. Left-Right
  10. ________ remain in memory even when all objects of a class have been destroyed.

    1. Static Variables
    2. Instance Variables
    3. Primitive Variables
    4. None of the given
  11. A template provides a convenient way to make a family of

    1. variables and data members
    2. functions and classes
    3. classes and exceptions
    4. programs and algorithms
  12. Which of the following is the correct syntax of declaring static variable "count" of type int?

    1. static count int;
    2. static int count;
    3. int static count;
    4. int count static;
  13. Which of the following statements best describes the Constructor?

    1. Constructor is used to modify constant data members of the class.
    2. Constructor is used to delete the objects of a class.
    3. Constructor is used to initialize the data members of a class.
    4. All of the given
  14. Mermaid is an example of:

    1. Single inheritance
    2. Polymorphism
    3. Specialization
    4. Multiple Inheritance
  15. The default inheritance mode is,

    1. Public inheritance
    2. Protected inheritance
    3. Private inheritance
    4. None of the given
  16. Suppose str1, str2 and str3 are objects of class String. Choose appropriate declaration of overloaded assignment operator for the following statement to work correctly.

    1. void operator =(const String &);
    2. String& operator =(const String &);
    3. String& overload =(const String &);
    4. void op =(const String &);
  17. In order to make any function constant, keyword const is placed at the ________ of the parameter list.

    1. Beginning
    2. Middle
    3. End
    4. None of the given
  18. In operator overloading, which of the following operator takes one or no argument.

    1. ++
    2. *
    3. %
    4. <<
  19. In case when we define the function outside the class then we must use the keyword ________ to make the function inline.

    1. requestin
    2. inlineout
    3. inline
    4. defineinline
  20. A pure virtual function is a virtual function that

    1. causes its class to be abstract.
    2. returns nothing.
    3. is used in a derived class.
    4. takes no arguments.
  21. Which of the following operators operate on one operand?

    1. Binary Operators
    2. Unary Operators
    3. Ternary Operator
    4. All of the given
  22. If you have three classes in a C++ program A, B, and C where class A inherits from class B, then class ________ contains all the characteristics of class ________.

    1. B, A
    2. A, B
    3. A, C
    4. B, C
  23. In which of the following OOP paradigm objects cannot exist independently?

    1. Polymorphism
    2. Inheritance
    3. Aggregation
    4. Composition
  24. How many entities are there in the following scenario?
    Ali lives in the house that is near the tree and he also drives his car.

    1. 1
    2. 2
    3. 3
    4. 4
  25. In C++, which of the following operator can only be overloaded as a member function of the class?

    1. Equality Operator: ==
    2. Inequality Operator: !=
    3. Function Operator: ()
    4. Stream Extraction Operator: >>
  26. In C++ by default access of classes is ________.

    1. Private
    2. Protected
    3. Public
    4. None of the given
  27. Consider the code below,
    class class1{
    protected:
    int i;
    };
    class class2 : private class1 {
    };

    Then int member i of class1 is ________ in class2.

    1. public
    2. protected
    3. private
    4. None of the given
  28. How can we differentiate between constructors and destructors?

    1. Destructors have a return type but Constructors do not have return type.
    2. Destructors can't be defined by the programmer, but Constructors can be defined by the programmer.
    3. Destructors are preceded with a tilde (~) symbol, and constructors are not preceded with any symbol.
    4. Destructors are exactly same as Constructors in syntax.
  29. In case of protected inheritance, public members of base class will be ________ in derived class?

    1. private
    2. public
    3. protected
    4. hidden
  30. We can have ________ type of member functions in a class.

    1. Public
    2. Private
    3. Protected
    4. All of the given
  31. Which of the following is TRUE.

    1. Derived class pointer can be used as Base class pointer
    2. Base class pointer can be used as Derived class pointer
    3. Both of these options
    4. None of the given
  32. If there is a pointer p to objects of a base class , and it contains the address of an object of a derived class, and both classes contain a virtual member function, ding(), then the statement p->ding(); will cause the version of ding() in the ________ class to be executed.

    1. base
    2. derived
    3. virtual
    4. implemented
  33. The other name of specialization is ________.

    1. Restriction
    2. Extension
    3. Dependency
    4. Subtyping
  34. ________ Binding means that target function for a call is selected at compile time.

    1. Static
    2. Dynamic
    3. Automatic
    4. None of the given
  35. How the information hidden within an object can be accessed?

    1. Through its interface
    2. Through its private data members
    3. Through its private member functions
    4. Through both public and private members
  36. The other name of specialization is ________.

    1. Restriction
    2. Extension
    3. Dependency
    4. Subtyping
  37. In expression c1*c2+c3-c4 which of the following will be executed in first order?

    1. c1*c2
    2. c2+c3
    3. c3-c4
    4. c1-c4
  38. In case of public inheritance, protected members of base class will be ________ in derived class.

    1. private
    2. public
    3. Protected
    4. hidden
  39. A Child class can call constructor of its parent class through,

    1. Its constructor initialization list
    2. Its constructor body
    3. Both from its constructor initialization list or body
    4. Can not call the constructor of its parent class
  40. Consider the following code segment:

    class test
    {
    int a;
    int b;
    int c;
    public:
    test():b(5).c(a).a(b){}
    }

    What will the value of variables a, b, and c after instantiating an object of above class?

    1. 5, 5, 5
    2. 5, Junk value, 5
    3. Junk value, 5, Junk value
    4. Junk value, 5, 5
  41. Which of the following classes are used by Amphibious vehicle to inherit characteristics?

    1. Land Vehicle
    2. Water Vehicle
    3. Both Land & Water Vehicle
    4. None of the given
  42. A good model is ________ related to a real life problem.

    1. Loosely
    2. Openly
    3. Closely
    4. Not
  43. How many objects are involved in the N-ary association?

    1. More than 1
    2. More than 2
    3. More than 3
    4. More than 4
  44. Insertion operator is ________ associative.

    1. Right to Left
    2. Left to Right
    3. Left to Left
    4. Right to Right
  45. Static casting is,

    1. Implicit way of calling base class functions from derived class
    2. Explicit way of calling base class functions from derived class
    3. Both of the given
    4. None of the given
  46. Which of the following is True about Destructor?

    1. It is used to free memory that is allocated through dynamic allocation.
    2. Free memory allocated using new operator by over self in destructor.
    3. It is used to perform house keeping operations.
    4. All of the given
  47. Class is blueprint of ________.

    1. Interface
    2. Class
    3. Objects
    4. Model
  48. Methodologies to the development of reusable software relate to ________.

    1. Structure programming
    2. procedural programming
    3. generic programming
    4. None of the given
  49. What is meant by multiple inheritance?

    1. Deriving a base class from derived class
    2. Deriving a derived class from base class
    3. Deriving a derived class from more than one base class
    4. None of the given
  50. Defining a function in class body, the compiler treats that function as:

    1. User defined function
    2. Static function
    3. Recursive function
    4. Inline function
  51. Assignment operators are:

    1. Left associative
    2. Right associative
    3. Left and right associative
    4. Non associative
  52. Which of the following is NOT casting operator in C++ standard?

    1. static_cast
    2. var_cast
    3. dynamic_cast
    4. reinterpret_cast
  53. Which of the following is a strong relationship?

    1. Inheritance
    2. Composition
    3. Association
    4. Polymorphism
  54. Which of the following concept is more close to encapsulation?

    1. Exception Handling
    2. Inheritance
    3. Polymorphism
    4. Information Hiding
  55. Consider the code below,
    class class1{
    public:
    int i;
    };
    class class2 : public class1 {
    };

    Then int member i of class1 is ________ in class2.

    1. public
    2. protected
    3. private
    4. None of the given
  56. Consider the statement "room has chair" Which of the following type of association exists between room and chair?

    1. Inheritance
    2. Composition
    3. There is no association
    4. Aggregation
  57. Suppose we have defined derived class copy constructor but have not defined base class copy constructor then compiler will,

    1. Use base class default constructor
    2. Generate base class copy constructor itself
    3. Use base class assignment operator
    4. None of the given
  58. Suppose for a class String, assignment operator is overloaded with following declaration.
    void operator =(const String &);
    What will happen when we will write following statement in main()?
    str1 = str2 = str3;
    Where, str1, str2 and str3 are objects of class String.

    1. Program will compile successfully.
    2. Compiler will generate compile time error.
    3. Run time error will be generated.
    4. None of the given
  59. How many objects of a given class may be constructed in an application?

    1. Only one per constructor.
    2. As many as the application asks for
    3. Only one per class
    4. One object per variable
  60. In C++ generic programming is done using ________.

    1. Procedures
    2. Packages
    3. Templates
    4. None of the given
  61. In C++, Composition is a relationship between ________ and ________ objects.

    1. Parent, child
    2. Base, derived
    3. Whole, part
    4. All of the given
  62. Choose correct declaration of overloaded stream insertion operator for class String as non-member friend function.

    1. friend ostream & operator << ();
    2. friend void & operator << (ostream & os);
    3. friend void operator << (const String & rhs);
    4. friend ostream & operator << (ostream & os, const String & s);
  63. Abstraction provides information according to ________.

    1. User perspective
    2. Owner perspective
    3. Random information
    4. All information
  64. Function overriding is done in context of,

    1. Single class
    2. Single derived class
    3. Single base class
    4. Derived and base class
  65. A template argument is preceded by the keyword ________.

    1. vector
    2. class
    3. template
    4. type*
  66. What is the output of the following code?

    int main()
    {
    int const x = 10;
    cout << ++x;
    return 0;
    }

    1. 10
    2. 11
    3. Error
    4. None of the given
  67. We can access a private static variable through:

    1. Static data member
    2. Static member function
    3. Global data member
    4. None of the given
  68. ________ defines the order of evaluation of an operator in an expression.

    1. Operator Associativity
    2. Operator Precedence
    3. Arity of Operators
    4. None of the given
  69. Which of the following can be the attribute of an object "Ali"?

    1. Eat
    2. Walk
    3. Sleep
    4. Address
  70. The ________ tells the compiler what task the function will be performing.

    1. Function declaration
    2. Function calling
    3. Function definition
    4. None of the given
  71. ________ is represented by a line with an unfilled diamond head towards the container.

    1. Inheritance
    2. Association
    3. Aggregation
    4. Composition
  72. The overloaded '-' operator for Complex class will be called with reference to ________ in the following statement
    Complex C3 = C1 - C2;

    1. Complex
    2. C1
    3. C2
    4. C3
  73. In Protected Inheritance the public members of base class become ________ in derived class.

    1. Public
    2. Private
    3. Protected
    4. None of the given
  74. Static Data Member is declared ________.

    1. Inside the class
    2. Outside the class
    3. Inside main() method
    4. None of the given
  75. Compiler generated copy constructor performs ________.

    1. Shallow copy
    2. Deep copy
    3. Both Shallow and Deep copy
    4. None of the given
  76. Subtyping means that derived class is behaviorally ________ with the base class.

    1. Same
    2. Compatible
    3. Different
    4. Incompatible
  77. Which of the following can be the behavior of an object "Usman"?

    1. Name
    2. Age
    3. Address
    4. Eat
  78. "Student registers Course and Teacher teaches the Course." is an example of:

    1. Binary Association
    2. Two way Association
    3. Ternary Association
    4. N-ary Association
  79. Identify the abstract class from the given statement:

    "Vehicle class is base class. Bus, Car, and Truck are derived classes"

    1. Vehicle
    2. Bus
    3. Car
    4. Truck
  80. Constructors have ________ return type.

    1. int
    2. char
    3. void
    4. no
  81. Suppose there is an object of type Person, which of the following can be considered as one of its attributes?

    1. Name
    2. Eat
    3. Work
    4. Sleep
  82. If class B inherits from class A then it contains all characteristics of ________.

    1. Class B
    2. Class A
    3. No inheritance
    4. None of the given
  83. Polymorphism makes the system:

    1. reusable
    2. flexible
    3. faster
    4. All of the given
  84. Which of the following types of Inheritance is used to model "Implemented in terms of" relationship?

    1. Public
    2. Private
    3. Protected
    4. Confidential
  85. Consider the code below,

    class class1{
    private:
    void func1();
    };
    class class2 : private class1 {
    };
    Function func1 of class1 is ________ in class2.

    1. public
    2. protected
    3. private
    4. None of the given