Knowee
Questions
Features
Study Tools

Select the correct answerWhat will happen if we provide concrete implementation of method in interface?OptionsThe concrete class implementing that method need not provide implementation of that methodCompilation failureMethod not found exception is thrownRuntime exception is thrown

Question

Select the correct answerWhat will happen if we provide concrete implementation of method in interface?OptionsThe concrete class implementing that method need not provide implementation of that methodCompilation failureMethod not found exception is thrownRuntime exception is thrown

🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct answer is "Compilation failure".

Here's why:

In Java, an interface is a reference type, similar to a class, that can contain only constants, method signatures, default methods, static methods, and nested types. Method bodies exist only for default methods and static methods. Writing concrete methods in interfaces was not allowed until Java 8 introduced default methods and static methods.

However, if you provide a concrete implementation of a method in an interface (without using default or static), it will result in a compilation failure. This is because it violates the design principle of interfaces, which are meant to provide a contract for the classes to implement, not to provide an implementation.

This problem has been solved

Similar Questions

Select the correct answerWhat happens when a constructor is defined for an interface?OptionsCompilation failureThe interface compiles successfullyThe implementing class will throw exceptionRuntime Exception

Select the correct answerWhat would be the result if a class extends two interfaces and both have a method with same name and signature? Lets assume that the class is not implementing that method.OptionsCompile time errorRuntime errorCode runs successfullyFirst called method is executed successfully

Select the correct answerWhich of the following does not have a body?OptionsAn InterfaceA ClassAn Abstract MethodNone of the mentioned

Select the correct answerWhich of these is not a correct statement?OptionsAbstract class defines only the structure of the class not its implementationEvery class containing abstract method must be declared abstractAbstract class can be initiated by new operatorAbstract class can be inherited

All methods must be implemented of an interface.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.