Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public class Test { private int x; private int y; private int z; public Test(){

ID: 3577262 • Letter: P

Question

public class Test {
   private int x;
   private int y;
   private int z;
   public Test(){
      
   }
   public Test(int x, int y, int z){
       this.x = x;
       this.y = y;
       this.z = z;
   }
   public String toString(){
       return "X = "+x+" Y = "+y+" Z = "+z;
   }
   public boolean equals(Test t){
       if(this.x == t.x && this.y == t.y && this.z == t.z){
           return true;
       }
       else{
           return false;
       }
   }
}

WRITE A COPY CONSTRUCTOR FOR THE PROGRAM ABOVE

Explanation / Answer

Test.java


public class Test {
   private int x;
   private int y;
   private int z;
   public Test(){
      
   }
   public Test(int x, int y, int z){
       this.x = x;
       this.y = y;
       this.z = z;
   }
   public Test(Test t){ //copy constructor
       this.x = t.x;
       this.y = t.y;
       this.z = t.z;
   }

   public String toString(){
       return "X = "+x+" Y = "+y+" Z = "+z;
   }
   public boolean equals(Test t){
       if(this.x == t.x && this.y == t.y && this.z == t.z){
           return true;
       }
       else{
           return false;
       }
   }
}