Skip to main content

Important Introduction to Programming Short Questions

Chapter: 39
Question 1:
How can you ensure that a copy constructor performs a deep copy?
Answer: By allocating new memory for the new object and copying the values from the original object into this new memory.
Chapter: 40
Question 2:
What is the construction order of objects in a class containing other class objects?
Answer: Contained objects are constructed before the containing object, and the containing object is destroyed first.
Chapter: 40
Question 3:
How does the destructor order relate to the constructor order in C++?
Answer: Destructors are called in the reverse order of constructors; the containing object is destroyed before contained objects.
Chapter: 40
Question 4:
How do you initialize contained objects in a class in C++?
Answer: Use the initializer list in the constructor of the containing class to initialize contained objects.
Chapter: 40
Question 5:
What is the role of the initializer list in class constructors?
Answer: It initializes contained objects directly, avoiding the need for setter methods and ensuring efficient construction.
Chapter: 40
Question 6:
In the PersonInfo class example, what is the construction order of birthday and drvLicenseDate?
Answer: birthday is constructed first, followed by drvLicenseDate, despite the order in the initializer list.
Chapter: 40
Question 7:
When creating a Matrix object, which class objects are constructed first?
Answer: The Column object is constructed first, followed by Row, and finally the Matrix object.
Chapter: 40
Question 8:
What happens if you declare a class object as public within another class?
Answer: The nested class is accessible from outside the containing class.
Chapter: 40
Question 9:
What happens if a nested class is declared in the private section of an outer class?
Answer: The nested class is only accessible within the containing class.
Chapter: 40
Question 10:
How are nested classes accessed within their containing class in C++?
Answer: They are accessed using the scope resolution operator (::).