Return to site

JAVA CERTIFICATION QUESTION: Working with abstract classes and default methods in Java

=>What happens when a default method is hidden and inaccessible?

· java

Given the following classes and an interface:

interface Flyable {
    public default void fly() {    
        System.out.print("Default fly");
    };
}

abstract class Bird implements Flyable {
    public abstract void fly();
}

class Chicken extends Bird implements Flyable {  
    public void fly() {    
        System.out.print("Cannot fly");
    };
}

class BirdsFarm {
    public static void main(String[] args) {
        Bird b = new Chicken();
        Flyable f = b;
        f.fly();    
    }
}

What is the result? Choose one.

A. The Bird class fails to compile.

B. The Chicken class fails to compile.

C. Default fly is printed.

D. Cannot fly is printed.

 

·ꓷ sᴉ ɹǝʍsuɐ ʇɔǝɹɹoɔ ǝɥꓕ