+ 2
Identify and explain two reasons why this code may not function as intended.
public class Tyre { private int treadRemaining; public void SetTread(int t) { treadRemaining=t; } public int GetTread() { return treadRemaining; } } public class Car extends Vehicle implements Cloneable { private Tyre tyres[] = new Tyre[4]; public Car() { for (int i=0; i<4; i++) tyres[i] = new Tyre(); } public Object clone() throws CloneNotSupportedException { Car c = new Car(); c.tyres = this.tyres; return c; } } //Q 1 . Identify and explain two reasons why this code may not function as intended. Q 2. Rewrite the code to address the problems you have identified and allow Car objects to be fully cloned. Q3Identify the type of interface that Cloneable is. What is the defining characteristic of such interfaces?
1 Réponse
0
Should be public: and private: (and the comments, because they aren't one-line and you use // instead of /*... */