Below are the two parts of the question, and I have answered part (c) and given
ID: 3787939 • Letter: B
Question
Below are the two parts of the question, and I have answered part (c) and given a possible answer to (d). However, I am not sure of its correctness. Please review and give me the full answer with explanation (I included my (c) answer because (d) references it.) Finally, I've included screenshots of the relevant code.
(c)If possible, give a test case that executes the fault, but does not result in an error state. If not, briefly explain why not.
The test method cloneSuper() executes the fault "new Vehicle(this.x)" in Vehicle.clone() at "Location A", but the result returned is in fact a field-for-field copy of the class. Further, the program counter (PC) is at the correct position after creating the 'clone' Vehicle class--that is, at "return result" just after "Location A". Therefore, this class executes the fault, but, without any of the variables including the PC being in an erroneous state, there is no error.
(d)If possible give a test case that results in an error, but not a failure. If not, briefly explain why not. Hint: Don’t forget about the program counter.
Unless the response to (c) is incorrect in assuming that the de facto result of the faulty clone() method in Vehicle is identical to a true "clone", there is no case that would result in an error and not a failure. However, if the assumption is incorrect (i.e. the de facto 'clone' is considered erroneous because it is not the proper 'clone'), then the test method cloneSuper() would in fact result in an error (i.e. erroneous state) but not a failure. The program counter in all cases appears to be correct, whether the faulty code or correct code is executed.
Note: the PC would be incorrect during its call to the Vehicle constructor in the clone method, as it should be chain-calling the super.clone() methods up to Object. However, once the object is returned from the constructor call, the PC would again be in the correct state.
_______________________________________________________________
The code consists of three files, Vehicle.java, Truck.java, and CloneTest.java. The Vehicle class is the superclass, the Truck the subclass, and CloneTest the JUnit test that tests with cloneSuper() and cloneSub() methods. The only "corrected code" is in the Vehicle class file, shown below.
CORRECTED CODE (with call to super.clone() rather than new Vehicle(this.x)):
Original Code Files:
Truck,java Vehide. java Clone Test java as Source History See also Truck java e public class Vehicle implements Cloneable private int x: 11 public vehicle (int y) f x y: O Goverride public object clone throws cloneNotsupportedException object result super clone ob ect result new vehicle (this x) Location "A" 16 17 return result; 18 eoverride public boolean equals (object o) if (o instanceof Vehicle)) return false; 20 21 Vehicle va (Vehicle) o 22 return v.x this .x Test Results Clone Test Tests passed 100.00 Both tests passed. (0.064s) Clone Test passed donesub passed (0.002 s) A done super passed (0.0 s)Explanation / Answer
I think the answer is correct.The problem is in overiding function.While overriding the object might be overwritten bt "this.x" object
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.