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



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)

Download Printable PDF. VALID exam to help you PASS.

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

  1. A : ( with correction: should be ArrayList ps = new ArrayList (); )
    # javac Test41.java
    Note: Test41.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    # java Test41
    Mike Found

  2. Answer is A

    class Patient{
    String name;
    public Patient(String name){
    this.name = name;
    }
    }

    public class Test {
    public static void main(String[] args) {
    List ps = new ArrayList();
    Patient p2 = new Patient(“Mike”);
    ps.add(p2);
    int f = ps.indexOf(p2);
    if (f >= 0){
    System.out.println(“Mike Found”);
    }
    }
    }

Leave a Reply

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


The reCAPTCHA verification period has expired. Please reload the page.