Given a snippet of an interface `A` in Java with a default method `print()`, and a class `B` that implements interface `A`, you need to fill in the blanks in the code to correctly implement the functionality. Additionally, there's a `main` method in class `Main`, which creates an instance of class `B` and calls the `print()` method. Ensure the code compiles and runs without errors, displaying the expected output.
Computer scienceProgramming languagesJavaCode organizationObject-oriented programmingClass hierarchiesInterfaces and abstract classes
Default methods
Implementing default method in Java interface
Report a typo
Fill in the gaps with the relevant elements
A {
print() {
System.out.println("Default method from interface A.");
}
}
class B A {}
public class Main {
public static void main(String[] args) {
B b = new B();
b.print();
}
} ___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.