FSc · Computer Science (Grade 12)

Unit 8 MCQs

49 solved multiple choice questions with answers.

Q1. A class is

  1. AA variable only
  2. BA blueprint or template for creating objects
  3. CA function only
  4. DAn instance of an object
Show answer
Answer: B. A blueprint or template for creating objects
Report a mistake

Q2. An object is

  1. AA data type only
  2. BA blueprint
  3. CAn instance of a class
  4. DA function
Show answer
Answer: C. An instance of a class
Report a mistake

Q3. The members of a class can be

  1. AData members and member functions
  2. BOnly constructors
  3. COnly data members
  4. DOnly functions
Show answer
Answer: A. Data members and member functions
Report a mistake

Q4. Access specifiers in C++ are

  1. AOnly private and public
  2. BOnly public
  3. Copen, closed, hidden
  4. Dprivate, public, protected
Show answer
Answer: D. private, public, protected
Report a mistake

Q5. By default, members of a class are

  1. Apublic
  2. Bprotected
  3. Cglobal
  4. Dprivate
Show answer
Answer: D. private
Report a mistake

Q6. By default, members of a structure are

  1. Aprivate
  2. Bprotected
  3. Cpublic
  4. Dhidden
Show answer
Answer: C. public
Report a mistake

Q7. public members are accessible

  1. AOnly in derived classes
  2. BFrom anywhere in the program
  3. COnly inside the class
  4. DOnly in main()
Show answer
Answer: B. From anywhere in the program
Report a mistake

Q8. private members are accessible

  1. AOnly outside the class
  2. BOnly inside the class itself
  3. COnly in derived classes
  4. DFrom anywhere
Show answer
Answer: B. Only inside the class itself
Report a mistake

Q9. protected members are accessible

  1. AFrom anywhere
  2. BOnly in main()
  3. CInside the class and its derived classes
  4. DOnly outside the class
Show answer
Answer: C. Inside the class and its derived classes
Report a mistake

Q10. Encapsulation is

  1. ABinding data and functions together and hiding details
  2. BInheriting classes
  3. CCreating multiple objects
  4. DOverloading functions
Show answer
Answer: A. Binding data and functions together and hiding details
Report a mistake

Q11. Data hiding is achieved by

  1. AUsing macros
  2. BMaking everything public
  3. CUsing global variables
  4. DMaking data members private
Show answer
Answer: D. Making data members private
Report a mistake

Q12. A constructor is

  1. AA special member function that initializes objects
  2. BAn operator
  3. CA destructor
  4. DA normal function
Show answer
Answer: A. A special member function that initializes objects
Report a mistake

Q13. Constructor has the same name as

  1. AAny function
  2. BThe class
  3. Cmain()
  4. DThe object
Show answer
Answer: B. The class
Report a mistake

Q14. Constructor has

  1. Afloat return type
  2. Bint return type
  3. CNo return type (not even void)
  4. Dvoid return type
Show answer
Answer: C. No return type (not even void)
Report a mistake

Q15. Default constructor takes

  1. AAny number
  2. BNo parameters
  3. COne parameter
  4. DTwo parameters
Show answer
Answer: B. No parameters
Report a mistake

Q16. Parameterized constructor takes

  1. AOne or more parameters
  2. BOnly default values
  3. COnly one parameter always
  4. DNo parameters
Show answer
Answer: A. One or more parameters
Report a mistake

Q17. Copy constructor is used to

  1. ADelete an object
  2. BInitialize with default values
  3. CConvert data types
  4. DCreate a new object as a copy of existing object
Show answer
Answer: D. Create a new object as a copy of existing object
Report a mistake

Q18. Destructor is called

  1. AAutomatically when object goes out of scope
  2. BAt the beginning of program
  3. COnly manually
  4. DNever
Show answer
Answer: A. Automatically when object goes out of scope
Report a mistake

Q19. Destructor name is preceded by

  1. AAsterisk (*)
  2. BAmpersand (&)
  3. CHash (#)
  4. DTilde (~)
Show answer
Answer: D. Tilde (~)
Report a mistake

Q20. A class can have

  1. ANo destructor
  2. BOnly constructors
  3. COnly one destructor
  4. DMultiple destructors
Show answer
Answer: C. Only one destructor
Report a mistake

Q21. this pointer points to

  1. AThe current object
  2. BGlobal data
  3. CThe previous object
  4. DNULL always
Show answer
Answer: A. The current object
Report a mistake

Q22. Static data members

  1. ABelong to the class (shared by all objects)
  2. BBelong to each object separately
  3. CAre always private
  4. DCannot be accessed
Show answer
Answer: A. Belong to the class (shared by all objects)
Report a mistake

Q23. Static member functions can access

  1. ABoth static and non-static members
  2. BOnly non-static members
  3. COnly static members of the class
  4. DOnly global variables
Show answer
Answer: C. Only static members of the class
Report a mistake

Q24. Friend function is

  1. ACannot access private data
  2. BNot a member but can access private members
  3. CA member function
  4. DAlways private
Show answer
Answer: B. Not a member but can access private members
Report a mistake

Q25. Friend function is declared using keyword

  1. Aprivate
  2. Bpublic
  3. Cstatic
  4. Dfriend
Show answer
Answer: D. friend
Report a mistake

Q26. Operator overloading means

  1. AOnly using arithmetic operators
  2. BGiving special meaning to operators for user-defined types
  3. CCreating new operators
  4. DRemoving operators
Show answer
Answer: B. Giving special meaning to operators for user-defined types
Report a mistake

Q27. Which operators cannot be overloaded?

  1. A+ and –
  2. B* and /
  3. C:: , .* , . , ?:
  4. D&& and ||
Show answer
Answer: C. :: , .* , . , ?:
Report a mistake

Q28. Inheritance allows

  1. AOnly creating objects
  2. BA class to acquire properties of another class
  3. COnly overloading
  4. DOnly hiding data
Show answer
Answer: B. A class to acquire properties of another class
Report a mistake

Q29. The class that is inherited from is called

  1. AFriend class
  2. BChild class only
  3. CDerived class
  4. DBase class / Parent class
Show answer
Answer: D. Base class / Parent class
Report a mistake

Q30. The class that inherits is called

  1. ABase class
  2. BAbstract class only
  3. CParent class
  4. DDerived class / Child class
Show answer
Answer: D. Derived class / Child class
Report a mistake

Q31. Types of inheritance in C++ include

  1. AOnly multiple
  2. BOnly multilevel
  3. CSingle, Multiple, Multilevel, Hierarchical, Hybrid
  4. DOnly single
Show answer
Answer: C. Single, Multiple, Multilevel, Hierarchical, Hybrid
Report a mistake

Q32. Multiple inheritance means

  1. AA class inherits from only one class
  2. BA class inherits from more than one base class
  3. CMany classes inherit from one
  4. DNo inheritance
Show answer
Answer: B. A class inherits from more than one base class
Report a mistake

Q33. Visibility mode in inheritance can be

  1. AOnly private
  2. BOnly public
  3. Cpublic, private, protected
  4. DOnly protected
Show answer
Answer: C. public, private, protected
Report a mistake

Q34. When inheritance is public

  1. AMembers are hidden
  2. BAll members become private
  3. CAll members become protected
  4. Dpublic members of base remain public in derived
Show answer
Answer: D. public members of base remain public in derived
Report a mistake

Q35. Polymorphism means

  1. ACreating classes
  2. BOnly one form
  3. CMany forms (ability to take multiple forms)
  4. DHiding data
Show answer
Answer: C. Many forms (ability to take multiple forms)
Report a mistake

Q36. Compile-time polymorphism is achieved by

  1. AVirtual functions
  2. BFunction overloading and operator overloading
  3. COnly encapsulation
  4. DOnly inheritance
Show answer
Answer: B. Function overloading and operator overloading
Report a mistake

Q37. Run-time polymorphism is achieved by

  1. AOnly templates
  2. BFunction overloading
  3. COperator overloading
  4. DVirtual functions
Show answer
Answer: D. Virtual functions
Report a mistake

Q38. Virtual function is declared using keyword

  1. Astatic
  2. Binline
  3. Cvirtual
  4. Dfriend
Show answer
Answer: C. virtual
Report a mistake

Q39. Pure virtual function has

  1. AOnly empty body
  2. BReturn type void only
  3. CDeclaration ending with = 0
  4. DNo declaration
Show answer
Answer: C. Declaration ending with = 0
Report a mistake

Q40. A class containing pure virtual function is called

  1. AAbstract class
  2. BFriend class
  3. CConcrete class
  4. DStatic class
Show answer
Answer: A. Abstract class
Report a mistake

Q41. Abstract class

  1. AHas no members
  2. BCan be instantiated freely
  3. CCannot be instantiated (no objects)
  4. DIs always final
Show answer
Answer: C. Cannot be instantiated (no objects)
Report a mistake

Q42. Constructor is called when

  1. AAn object is destroyed
  2. BFunction is called
  3. CProgram ends
  4. DAn object is created
Show answer
Answer: D. An object is created
Report a mistake

Q43. Destructor is called when

  1. AProgram starts
  2. BAn object is created
  3. CAn object is destroyed
  4. DFunction returns
Show answer
Answer: C. An object is destroyed
Report a mistake

Q44. Member functions defined inside the class are by default

  1. AStatic
  2. BFriend
  3. CInline
  4. DVirtual
Show answer
Answer: C. Inline
Report a mistake

Q45. Objects of a class can be created

  1. AOnly inside the class
  2. BOnly globally
  3. CNever
  4. DIn main() or any function
Show answer
Answer: D. In main() or any function
Report a mistake

Q46. The size of an empty class is

  1. A1 byte (usually)
  2. B0 byte
  3. C4 bytes
  4. D8 bytes
Show answer
Answer: A. 1 byte (usually)
Report a mistake

Q47. Data members are also known as

  1. AFunctions only
  2. BMethods only
  3. CAttributes / Properties
  4. DConstructors
Show answer
Answer: C. Attributes / Properties
Report a mistake

Q48. Member functions are also known as

  1. AMethods / Behaviors
  2. BData only
  3. CAttributes only
  4. DVariables
Show answer
Answer: A. Methods / Behaviors
Report a mistake

Q49. The main pillars of Object-Oriented Programming are

  1. AEncapsulation, Inheritance, Polymorphism (and Abstraction)
  2. BOnly variables and constants
  3. COnly loops and functions
  4. DOnly arrays and pointers
Show answer
Answer: A. Encapsulation, Inheritance, Polymorphism (and Abstraction)
Report a mistake