What is the result?

Given the code fragments:


What is the result?
A. Super
Sub
Sub
B. Contract
Contract
Super
C. Compilation fails at line n1
D. Compilation fails at line n2

Download Printable PDF. VALID exam to help you PASS.

0 thoughts on “What is the result?

  1. Option A.

    interface Contract { }

    class Super implements Contract { }

    class Sub extends Super { }

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

    List objs = new ArrayList();

    Contract c1 = new Super();
    Contract c2 = new Sub();
    Super s1 = new Sub();

    objs.add(c1);
    objs.add(c2);
    objs.add(s1);

    for (Object itm : objs)
    System.out.println(itm.getClass().getName());
    }
    }

    Output:
    test.Super
    test.Sub
    test.Sub

Leave a Reply

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


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