What is the result?

Given:


What is the result?
A. Shining Sun
Shining Sun
Shining Sun
B. Shining Sun
Twinkling Star
Shining Sun
C. Compilation fails
D. A ClassCastException is thrown at runtime

Download Printable PDF. VALID exam to help you PASS.

One thought on “What is the result?

  1. Option A.

    class Star {
    public void doStuff() {
    System.out.println(“Twinkling Star”);
    }
    }

    interface Universe {
    public void doStuff();
    }

    class Sun extends Star implements Universe {
    public void doStuff() {
    System.out.println(“Shining Sun”);
    }
    }

    public class Test {
    public static void main(String[] args) {
    Star obj2 = new Sun();
    Star obj3 = obj2;
    ((Sun) obj3).doStuff();
    ((Star) obj2).doStuff();
    ((Universe) obj2).doStuff();
    }
    }

    Output:
    Shining Sun
    Shining Sun
    Shining Sun

Leave a Reply

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


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