Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Multiple Choice Questions
Q451: In object-oriented programming, what are the building blocks of a program?
- A: Functions and variables
- B: Classes and objects
- C: Strings and arrays
- D: Data members and methods
View Answer
B
Q452: What concept allows data in a class to be accessed only through defined functions?
- A: Encapsulation
- B: Inheritance
- C: Polymorphism
- D: Abstraction
View Answer
A
Q453: Which part of the class is visible to functions outside the class?
- A: Public interface
- B: Private data members
- C: Protected members
- D: Implementation details
View Answer
A
Q454: What is the role of a constructor in a class?
- A: To initialize data members
- B: To define member functions
- C: To delete objects
- D: To access private data members
View Answer
A
Q455: What type of constructor does the compiler provide automatically if no constructor is defined?
- A: Default constructor
- B: Parameterized constructor
- C: Simple constructor
- D: Overloaded constructor
View Answer
A
Q456: What is the primary use of parameterized constructors?
- A: To initialize data members with specific values
- B: To create default objects
- C: To delete objects
- D: To access private functions
View Answer
A
Q457: Which of the following statements about constructor overloading is true?
- A: Multiple constructors can be defined with different parameter lists
- B: Constructors cannot be overloaded
- C: All constructors must take at least one argument
- D: Constructors cannot have default arguments
View Answer
A
Q458: What happens if no constructor is defined in a class?
- A: The compiler provides a default constructor
- B: The program will not compile
- C: The class will not have data members
- D: The class will have a runtime error
View Answer
A
Q459: How can you validate data before assigning it to data members in a class?
- A: Use set functions in the public part of the class
- B: Use private member functions
- C: Use destructors
- D: Use friend functions
View Answer
A
Q460: What is the purpose of a destructor in a class?
- A: To deallocate memory and clean up resources
- B: To initialize data members
- C: To provide default values
- D: To define new data members
View Answer
A