Question
Please explain why the correct answer is correct. Q1.1: Which of the following is a valid constructor for the class above? a) void MyInt(int val)
Please explain why the correct answer is correct.
Q1.1:
Which of the following is a valid constructor for the class above?
a) void MyInt(int val) { n = val; }
b) void MyInt(int val) : n(val) { }
c) MyInt(int val) : val(n) { }
d) MyInt(int n) : n(n) { }
Q1.2: In the driver program above, replace /* construct object */ with MyInt k(5); Assuming the correct answer to Q1.1, what happens when you try to compile and run the program?
a) It doesn't compile
b) It throws a runtime erro
c) It outputs 0
d) It outputs 2
e) It outputs 5
f) It outputs 7
Q1.3: In the driver program above, replace /* construct object */ with MyInt k; Assuming the correct answer to Q1.1, what happens when you try to compile and run the program?
a) It doesn't compile
b) It throws a runtime error
c) It outputs 0
d) It outputs 2
e) It outputs 5
f) It outputs 7
The code snippet gives a simple class and driver program, with a line missing from each. #importStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started