Mcq On Java Interfaces
16. What type of methods an interface contain by default?
Explanation: By default, interface contains abstract methods. The abstract methods need to be implemented by concrete classes.
17. What will happen if we provide concrete implementation of method in interface?
Explanation: The methods of interfaces are always abstract. They provide only method definition.
$ javac interfaces.java
$ java interfaces
18. What happens when a constructor is defined for an interface?
Explanation: Constructor is not provided by interface as objects cannot be instantiated.
19. What happens when we access the same variable defined in two interfaces implemented by the same class?
Explanation: The JVM needs to distinctly know which value of variable it needs to use. To avoid confusion to the JVM interfaceName.variableName is mandatory.
20. Can “abstract” keyword be used with constructor, Initialization Block, Instance Initialization and Static Initialization Block.
Explanation: No, Constructor, Static Initialization Block, Instance Initialization Block and variables cannot be abstract.
Also check :