17 Which of the following statements are true?

  1. a. An interface can only contain method and not variables

  2. b. Interfaces cannot have constructors

  3. c. A class may extend only one other class and implement only one interface

  4. d. Interfaces are the Java approach to addressing its lack of multiple inheritance, but require implementing classes to create the functionality of the Interfaces.


Correct Option: B

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) An interface can only contain methods and not variables - This option is incorrect. Interfaces can contain both methods and variables. In Java, interface variables are by default public, static, and final.

Option B) Interfaces cannot have constructors - This option is correct. Interfaces cannot have constructors because they are not meant to be instantiated directly. They are used as a blueprint for classes that implement them.

Option C) A class may extend only one other class and implement only one interface - This option is incorrect. In Java, a class can extend only one other class, but it can implement multiple interfaces. This is known as multiple interface inheritance.

Option D) Interfaces are the Java approach to addressing its lack of multiple inheritance, but require implementing classes to create the functionality of the interfaces - This option is incorrect. Interfaces in Java are used for abstraction and defining contracts. They do not provide functionality themselves. Implementing classes are responsible for providing the implementation of the methods defined in the interface.

The correct answer is B) Interfaces cannot have constructors.

Find more quizzes: