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 62 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
YES! Correct, THANKS for helping me on my review


mochi09

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

 

Did you know?

It is widely believed that giving a daily oral dose of aspirin to heart attack patients improves their chances of survival because the aspirin blocks the formation of new blood clots.

Did you know?

To combat osteoporosis, changes in lifestyle and diet are recommended. At-risk patients should include 1,200 to 1,500 mg of calcium daily either via dietary means or with supplements.

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?

According to animal studies, the typical American diet is damaging to the liver and may result in allergies, low energy, digestive problems, and a lack of ability to detoxify harmful substances.

Did you know?

Hyperthyroidism leads to an increased rate of metabolism and affects about 1% of women but only 0.1% of men. For most people, this increased metabolic rate causes the thyroid gland to become enlarged (known as a goiter).

For a complete list of videos, visit our video library