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: 3583154 • Letter: T

Question

This question refers to the following Java classes D2 and D3: class D2 {int x, y; public D2(lnt x. lot y>{this.x = x; this.y = y;) public boolean equals(Object o) {If (! (0 lnstance of D2) {return false;) else {D2 d = (D2)o; return d.x == x && d.y == y;}) class D3 extends D2 {lnt z; public D3(lnt x, int y, int z){super(x, y); this.z = z;} public boolean equals(0bject o) {if (!(o lnstance of D3)){return false;} else {D3 d = (D3)o; return d. z == z && 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 = vi; 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);

Explanation / Answer

D3 v1= new D3(0,0,0);
       D3 v2=v1;
       System.out.println(v1==(D3)v2);

Output : True

         D3 v1= new D3(0,0,0);
       D2 v2= new D3(0, 0, 0);
       System.out.println(v1==v2);
Output : false
      

D2 v1= new D3(0,0,1);
       D3 v2= new D3(0, 0, 0);
       System.out.println(v1.equals(v2));
Output :false


D2 v1= new D2(0,0);
       D3 v2== new D3(0, 0, 2);//compilation error here compare is not allowed
       System.out.println(v2.equals(v1));

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