Chapter 8: MCQs on Basic Object-Oriented Programming Concepts in C++ | C++ Programming

Explore fundamental concepts of Object-Oriented Programming (OOP) with these 30 MCQs. Topics include classes and objects, constructors and destructors, access modifiers, and encapsulation in C++. Perfect for mastering core OOP principles.


MCQs on Basic Object-Oriented Programming (OOP) Concepts

Classes and Objects

  1. What is a class in C++?
    • a) A variable type
    • b) A blueprint for creating objects
    • c) A data structure used for functions
    • d) A type of loop
  2. Which of the following statements is true about objects?
    • a) Objects are a blueprint of classes
    • b) Objects are instances of classes
    • c) Objects do not have attributes
    • d) Objects only store functions
  3. In OOP, what does an object contain?
    • a) Only data
    • b) Only functions
    • c) Data and functions
    • d) Only public members
  4. Which keyword is used to define a class in C++?
    • a) object
    • b) new
    • c) class
    • d) struct
  5. What is the relationship between a class and an object?
    • a) Classes are instances of objects
    • b) Objects are instances of classes
    • c) They are the same
    • d) Classes contain only functions, while objects contain data

Constructors and Destructors

  1. What is the purpose of a constructor in a class?
    • a) To delete an object
    • b) To initialize objects of a class
    • c) To overload functions
    • d) To define data types
  2. Which of the following statements is true about destructors?
    • a) They are used to initialize an object
    • b) They are called automatically when an object is destroyed
    • c) They have parameters
    • d) They cannot be defined by the user
  3. How many constructors can a class have in C++?
    • a) Only one
    • b) Only two
    • c) One or more
    • d) None
  4. When is a destructor called in C++?
    • a) When an object is created
    • b) When an object goes out of scope or is deleted
    • c) When a function is called
    • d) When a class is defined
  5. Which of the following correctly defines a destructor in C++?
    • a) ~ClassName()
    • b) ClassName::~()
    • c) delete ClassName()
    • d) ClassName::~ClassName()
  6. Can constructors be overloaded in C++?
    • a) Yes, by defining multiple constructors with different parameters
    • b) No, constructors cannot be overloaded
    • c) Only if the class has no destructor
    • d) Only if the class has no private members
  7. Which type of constructor is automatically called when no arguments are provided?
    • a) Parameterized constructor
    • b) Copy constructor
    • c) Default constructor
    • d) Destructor
  8. Which of the following statements is true about the copy constructor?
    • a) It initializes an object by copying another object of the same class
    • b) It destroys an object
    • c) It is used to overload functions
    • d) It is automatically called when an object is deleted
  9. What is the role of a parameterized constructor?
    • a) It initializes members of an object with given arguments
    • b) It only destroys an object
    • c) It has no parameters
    • d) It is used to initialize private members only
  10. What is the syntax for declaring a default constructor in C++?
    • a) ClassName() {}
    • b) ~ClassName() {}
    • c) ClassName(void);
    • d) ClassName() with default

Access Modifiers (public, private, protected)

  1. What is the default access modifier for class members in C++?
    • a) Public
    • b) Private
    • c) Protected
    • d) None
  2. Which access modifier makes a class member accessible only within its own class?
    • a) Public
    • b) Private
    • c) Protected
    • d) Friend
  3. If a member is declared as public, where can it be accessed from?
    • a) Only within the class
    • b) Within the class and its derived classes
    • c) From anywhere in the program
    • d) Only within the same file
  4. Which access modifier allows derived classes to access members but restricts outside classes?
    • a) Public
    • b) Private
    • c) Protected
    • d) Friend
  5. What happens if no access modifier is specified for a class member in C++?
    • a) It defaults to public
    • b) It defaults to private
    • c) It defaults to protected
    • d) It becomes inaccessible
  6. In a class, if you want certain methods accessible only within the same class, which modifier should you use?
    • a) Public
    • b) Private
    • c) Protected
    • d) Static
  7. How does the protected access modifier affect member accessibility?
    • a) Accessible only within the class
    • b) Accessible within the class and derived classes
    • c) Accessible from anywhere in the program
    • d) Not accessible in any class
  8. Can a private member be accessed by an instance of the class?
    • a) Yes, directly
    • b) No, only through public methods
    • c) Yes, through inheritance
    • d) No, it is not accessible at all
  9. Which access modifier would you use to allow member access only within the same package?
    • a) Public
    • b) Private
    • c) Protected
    • d) Package
  10. Which of the following keywords is used to make a class accessible to other classes in the same package only?
    • a) private
    • b) protected
    • c) package
    • d) public

Encapsulation in C++

  1. What is encapsulation in C++?
    • a) A feature that allows inheritance
    • b) A mechanism of restricting access to certain details of an object
    • c) A way to write functions
    • d) A process for handling multiple objects
  2. How is encapsulation achieved in C++?
    • a) Through pointers
    • b) Through classes and access modifiers
    • c) Through arrays
    • d) Through operator overloading
  3. Why is encapsulation important in OOP?
    • a) It provides data hiding and security
    • b) It simplifies code without providing data hiding
    • c) It only focuses on function overloading
    • d) It helps perform arithmetic operations
  4. Which of the following best describes encapsulation?
    • a) Combining data and methods in a class
    • b) Using only private members
    • c) Using only public methods
    • d) Having global variables
  5. Which of the following is a benefit of encapsulation?
    • a) It enables data abstraction and hides details
    • b) It increases code redundancy
    • c) It makes data globally accessible
    • d) It allows only public access

Answer Table

QnoAnswer
1b) A blueprint for creating objects
2b) Objects are instances of classes
3c) Data and functions
4c) class
5b) Objects are instances of classes
6b) To initialize objects of a class
7b) They are called automatically when an object is destroyed
8c) One or more
9b) When an object goes out of scope or is deleted
10a) ~ClassName()
11a) Yes, by defining multiple constructors with different parameters
12c) Default constructor
13a) It initializes an object by copying another object of the same class
14a) It initializes members of an object with given arguments
15a) ClassName() {}
16b) Private
17b) Private
18c) From anywhere in the program
19c) Protected
20b) It defaults to private
21b) Private
22b) Accessible within the class and derived classes
23b) No, only through public methods
24d) Package
25c) package
26b) A mechanism of restricting access to certain details of an object
27b) Through classes and access modifiers
28a) It provides data hiding and security
29a) Combining data and methods in a class
30a) It enables data abstraction and hides details

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top