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 55 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
Wow, this really help


carlsona147

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

 

Did you know?

One way to reduce acid reflux is to lose two or three pounds. Most people lose weight in the belly area first when they increase exercise, meaning that heartburn can be reduced quickly by this method.

Did you know?

According to research, pregnant women tend to eat more if carrying a baby boy. Male fetuses may secrete a chemical that stimulates their mothers to step up her energy intake.

Did you know?

Common abbreviations that cause medication errors include U (unit), mg (milligram), QD (every day), SC (subcutaneous), TIW (three times per week), D/C (discharge or discontinue), HS (at bedtime or "hours of sleep"), cc (cubic centimeters), and AU (each ear).

Did you know?

The immune system needs 9.5 hours of sleep in total darkness to recharge completely.

Did you know?

Automated pill dispensing systems have alarms to alert patients when the correct dosing time has arrived. Most systems work with many varieties of medications, so patients who are taking a variety of drugs can still be in control of their dose regimen.

For a complete list of videos, visit our video library