What will be the output of the following code?

interface I_A { public void out1(); }
interface I_B { public void out2(); }

class Impl implements I_A, I_B { // 1
    public void out2() {
    public void out1() {

public class Test {
    public static void main(String[] args) {
        Impl impl = new Impl();
        I_A a;
        a = impl;
        ((I_B) a).out2();  // 2
It is permitted to implement more than one interface in Java. Since Impl class implements both interfaces, casting an Impl object to either of them is also permitted.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Sign Up Now
or Subscribe for future quizzes