What is the result?

Given the class definitions:


And the code fragment of the main() method,


What is the result?
A. Java
Java
Java
B. Java
Jeve va
C. Java
Jeve ve
D. Compilation fails

Download Printable PDF. VALID exam to help you PASS.

One thought on “What is the result?

  1. Correct answer is B. as DonBa says:

    class Alpha {
    public String doStuff(String msg) {
    return msg;
    }
    }

    class Beta extends Alpha {
    public String doStuff(String msg) {
    return msg.replace(‘a’, ‘e’);
    }
    }

    class Gamma extends Beta {
    public String doStuff(String msg) {
    return msg.substring(2);
    }
    }

    public class Test {
    public static void main(String[] args) {

    List strs = new ArrayList();
    strs.add(new Alpha());
    strs.add(new Beta());
    strs.add(new Gamma());

    for (Alpha t : strs) {
    System.out.println(t.doStuff(“Java”));
    }
    }
    }

    Output:
    Java
    Jeve
    va

Leave a Reply

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


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