Java Programming MCQ Questions - Interfaces
11. Which of these keywords is used by a class to use an interface defined previously?
Explanation: interface is inherited by a class using implements.
12. Which is the correct way to inherit and implement the interface?
Explanation: Classes always implements an interface. An interface can extends another interface or multiple interfaces. Hence, answer would be A.
13. which of the following is true about methods in an interface in java?
Explanation: In java, an interface contains only abstract method that can be public and it does not have any method implementation.
14. Which of the following is the correct way of implementing an interface salary by class manager?
Explanation: No Explanation.
15. Which of the following is an incorrect statement about packages?
Explanation: All methods and variables are implicitly public if interface is declared public.
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. Output: $ javac interfaces.java $ java interfaces 4
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 :