Saved What does the following code output? (What's the order of construction/destruction)

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 23SA
icon
Related questions
Question

Need help with C++

What does the following code output? (What's the order of construction/destruction) saved
+include <iostream>
class Transmission
public:
Transmission () { std::cout ce "Transmission (0" « std::endl: }
-Transmission (0 { std::cout « *-Transmission ()" « std::endl: }
class Adapter {
public:
Adapter () ( std::cout <« "Adapter ()" <« std::endl: )
-Adapter () { std::cout <« *-Adapter ()" « std::endl: }
class Vehicle (
public:
Vehicle () ( std::cout << "Vehicle ()" « std::endl: )
-Vehicle () ( std::cout <« -Vehicle ()" « std::endl:}
class Car : public Vehicle {
public:
Car (): Vehicle () { std::cout « "Car ()" « std::endl: }
-Car () ( std::cout <« *-Car ()* « std::endl: }
private:
Transmission tran:
class Hybrid : public Car {
public:
Hybrid(): Car 0 ( std::cout « "Hybrid() <e std::endl: }
-Bybrid () { std::cout <« -Hybrid()" <« std::endl: }
private:
Adapter power:
int main()
Hybrid nycar:
Write your answer here..
Transcribed Image Text:What does the following code output? (What's the order of construction/destruction) saved +include <iostream> class Transmission public: Transmission () { std::cout ce "Transmission (0" « std::endl: } -Transmission (0 { std::cout « *-Transmission ()" « std::endl: } class Adapter { public: Adapter () ( std::cout <« "Adapter ()" <« std::endl: ) -Adapter () { std::cout <« *-Adapter ()" « std::endl: } class Vehicle ( public: Vehicle () ( std::cout << "Vehicle ()" « std::endl: ) -Vehicle () ( std::cout <« -Vehicle ()" « std::endl:} class Car : public Vehicle { public: Car (): Vehicle () { std::cout « "Car ()" « std::endl: } -Car () ( std::cout <« *-Car ()* « std::endl: } private: Transmission tran: class Hybrid : public Car { public: Hybrid(): Car 0 ( std::cout « "Hybrid() <e std::endl: } -Bybrid () { std::cout <« -Hybrid()" <« std::endl: } private: Adapter power: int main() Hybrid nycar: Write your answer here..
Expert Solution
Constructor and Destructor

The Constructors are called automatically whenever an instance of that class is created and destructors are called automatically when the instance losses its scope or memory allocated to it

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Structured English
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning