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

Author Question: Analyze the following code:public class Test1 { public Object max(Object o1, Object o2) {if ... (Read 57 times)

cherise1989

  • Hero Member
  • *****
  • Posts: 555

Question 1

Suppose A is an interface, B is a concrete class with a default constructor that implements A. Which of the following is correct?
◦ B b = new B();
◦ B b = new A();
◦ A a = new A();
◦ A a = new B();

Question 2

Analyze the following code:

public class Test1 {
public Object max(Object o1, Object o2) {
if ((Comparable)o1.compareTo(o2) >= 0) {
return o1;
}
else {
return o2;
}
}
}

◦ The program would compile if ((Comparable)o1.compareTo(o2) >= 0) is replaced by (((Comparable)o1).compareTo(o2) >= 0).
◦ The program has a compile error because you cannot cast an Object instance o1 into Comparable.
◦ The program has a compile error because Test1 does not have a main method.
◦ The program has a compile error because o1 is an Object instance and it does not have the compareTo method.


Related Topics

Need homework help now?

Ask unlimited questions for free

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

billybob123

  • Sr. Member
  • ****
  • Posts: 336
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




cherise1989

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


DylanD1323

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

 

Did you know?

Earwax has antimicrobial properties that reduce the viability of bacteria and fungus in the human ear.

Did you know?

After a vasectomy, it takes about 12 ejaculations to clear out sperm that were already beyond the blocked area.

Did you know?

Amphetamine poisoning can cause intravascular coagulation, circulatory collapse, rhabdomyolysis, ischemic colitis, acute psychosis, hyperthermia, respiratory distress syndrome, and pericarditis.

Did you know?

The Centers for Disease Control and Prevention (CDC) was originally known as the Communicable Disease Center, which was formed to fight malaria. It was originally headquartered in Atlanta, Georgia, since the Southern states faced the worst threat from malaria.

Did you know?

The most common childhood diseases include croup, chickenpox, ear infections, flu, pneumonia, ringworm, respiratory syncytial virus, scabies, head lice, and asthma.

For a complete list of videos, visit our video library