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

This question refers to the following Java classes D2 and D3: class D2{int x, y:

ID: 3583163 • Letter: T

Question

This question refers to the following Java classes D2 and D3: class D2{int x, y: public D2 (int x, int y) {this.x = x; this.y = y;} public boolean equals(Object o){if (!(o instanced D2)){return false;} else {D2 d = (D2)o; return d.x == x & d.y == y;}}} class D3 extends D2 {int z; public D3(int x, int y, int z){super(x, y); this.z = z;} public boolean equals(Object o) {if (!(o instanceof D3)){return false;} else {D3 d = (D3)o; return d.z == kk super.equals(o);}}} Consider each of the following code snippets. Does it result in a compile error or a runtime error? If no, what is the output? D3 v1 = new D3(0, 0, 0); D2 v2 = v1; System.out.println (v1 == (D3)v2); D3 v1 = new D3 (0, 0, 0); D2 v2 = new D3 (0, 0, 0); System.out.println(v1==v2); D2 v1 = new D3(0, 0, 1); D3 v2 = new D3 (0, 0, 0); System.out.println(v1.equals(v2)); D2 v1 = new D2 (0, 0); D3 v2 == new D3 (0, 0, 0); System.out.println(v2.equals(v1));

Explanation / Answer

output

(2.3)

D2 v1 = new D3(0,0,1)

D3 v2 = new D3(0,0,1)

System.out.println(v1.equals(v2))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote