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. #import
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
