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 58 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
Excellent


Laurenleakan

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

 

Did you know?

Many of the drugs used by neuroscientists are derived from toxic plants and venomous animals (such as snakes, spiders, snails, and puffer fish).

Did you know?

Oxytocin is recommended only for pregnancies that have a medical reason for inducing labor (such as eclampsia) and is not recommended for elective procedures or for making the birthing process more convenient.

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?

Although not all of the following muscle groups are commonly used, intramuscular injections may be given into the abdominals, biceps, calves, deltoids, gluteals, laterals, pectorals, quadriceps, trapezoids, and triceps.

Did you know?

The heart is located in the center of the chest, with part of it tipped slightly so that it taps against the left side of the chest.

For a complete list of videos, visit our video library