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 63 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
Great answer, keep it coming :)


ricroger

  • Member
  • Posts: 352
Reply 3 on: Yesterday
Gracias!

 

Did you know?

Intradermal injections are somewhat difficult to correctly administer because the skin layers are so thin that it is easy to accidentally punch through to the deeper subcutaneous layer.

Did you know?

The first war in which wide-scale use of anesthetics occurred was the Civil War, and 80% of all wounds were in the extremities.

Did you know?

Calcitonin is a naturally occurring hormone. In women who are at least 5 years beyond menopause, it slows bone loss and increases spinal bone density.

Did you know?

In 1835 it was discovered that a disease of silkworms known as muscardine could be transferred from one silkworm to another, and was caused by a fungus.

Did you know?

Patients who cannot swallow may receive nutrition via a parenteral route—usually, a catheter is inserted through the chest into a large vein going into the heart.

For a complete list of videos, visit our video library