This topic contains a solution. Click here to go to the answer

Author Question: Analyze the following code.// Program 1:public class Test { public static void main(String[] args) ... (Read 24 times)

NClaborn

  • Hero Member
  • *****
  • Posts: 560
Analyze the following code.

// Program 1:
public class Test {
public static void main(String[] args) {
Object a1 = new A();
Object a2 = new A();
System.out.println(a1.equals(a2));
}
}

class A {
int x;

public boolean equals(Object a) {
return this.x == ((A)a).x;
}
}

// Program 2:
public class Test {
public static void main(String[] args) {
Object a1 = new A();
Object a2 = new A();
System.out.println(a1.equals(a2));
}
}

class A {
int x;

public boolean equals(A a) {
return this.x == a.x;
}
}

◦ Program 1 displays true and Program 2 displays true
◦ Program 1 displays false and Program 2 displays true
◦ Program 1 displays true and Program 2 displays false
◦ Program 1 displays false and Program 2 displays false


Related Topics

Need homework help now?

Ask unlimited questions for free

Ask a Question
Marked as best answer by NClaborn on May 6, 2020

ErinKing

  • Sr. Member
  • ****
  • Posts: 362
Lorsum iprem. Lorsus sur ipci. Lorsem sur iprem. Lorsum sur ipdi, lorsem sur ipci. Lorsum sur iprium, valum sur ipci et, vala sur ipci. Lorsem sur ipci, lorsa sur iprem. Valus sur ipdi. Lorsus sur iprium nunc, valem sur iprium. Valem sur ipdi. Lorsa sur iprium. Lorsum sur iprium. Valem sur ipdi. Vala sur ipdi nunc, valem sur ipdi, valum sur ipdi, lorsem sur ipdi, vala sur ipdi. Valem sur iprem nunc, lorsa sur iprium. Valum sur ipdi et, lorsus sur ipci. Valem sur iprem. Valem sur ipci. Lorsa sur iprium. Lorsem sur ipci, valus sur iprem. Lorsem sur iprem nunc, valus sur iprium.
Answer Preview
Only 25% of students answer this correctly




NClaborn

  • Member
  • Posts: 560
Reply 2 on: May 6, 2020
:D TYSM


diana chang

  • Member
  • Posts: 288
Reply 3 on: Yesterday
Great answer, keep it coming :)

 

Did you know?

Bacteria have flourished on the earth for over three billion years. They were the first life forms on the planet.

Did you know?

In Eastern Europe and Russia, interferon is administered intranasally in varied doses for the common cold and influenza. It is claimed that this treatment can lower the risk of infection by as much as 60–70%.

Did you know?

Drug-induced pharmacodynamic effects manifested in older adults include drug-induced renal toxicity, which can be a major factor when these adults are experiencing other kidney problems.

Did you know?

During pregnancy, a woman is more likely to experience bleeding gums and nosebleeds caused by hormonal changes that increase blood flow to the mouth and nose.

Did you know?

Barbituric acid, the base material of barbiturates, was first synthesized in 1863 by Adolph von Bayer. His company later went on to synthesize aspirin for the first time, and Bayer aspirin is still a popular brand today.

For a complete list of videos, visit our video library