Which code fragment, when inserted at line 14, enables …

Given:

And the code fragment:

Which code fragment, when inserted at line 14, enables the code to print Mike Found?

Given:

And the code fragment:

Which code fragment, when inserted at line 14, enables the code to print Mike Found?

A.
int f = ps.indexOf (p2)

B.
int f = ps.indexOf (Patient (“Mike”) );

C.
int f = ps.indexOf (new Patient “Mike”) );

D.
Patient p = new Patient (“Mike”);
Int f = ps.indexOf (p)



Leave a Reply 5

Your email address will not be published. Required fields are marked *


ana

ana

D – is the correct answer

sil

sil

The answer is A

renko

renko

Answer: A
package q029;

class Patient {
String name;
public Patient(String name) {
this.name = name;
}
}
package q029;
import java.util.ArrayList;
public class Test {

public static void main(String[] args) {
ArrayList ps = new ArrayList();
Patient p2 = new Patient(“Mike”);
ps.add(p2);

//insert code here
int f = ps.indexOf(p2);

if (f >= 0) {
System.out.println(“Mike Found”);
}

}

}
Output:
Mike Found

rfvc

rfvc

A. correct answer

B. NOT, doesn’t have the new keyword.
int f = ps.indexOf (Patient (“Mike”) );

C and D. NOT because
Patient p = new Patient (“Mike”);
Int f = ps.indexOf (p) create a new object reference. unless overwrite equals method in Patient class would work with this answers.