VOOZH about

URL: https://www.geeksforgeeks.org/quizzes/java-interfaces/

⇱ Quiz about Java Interfaces


Last Updated :
Discuss
Comments

Question 1

Which of the following statements about Java interfaces is true?

  • An interface can have instance variables

  • An interface can extend multiple interfaces

  • An interface can implement another interface

  • An interface can have a constructor

Question 2

What is the correct way to declare an interface in Java?

  • interface MyInterface { void myMethod() {}; }


  • abstract interface MyInterface { void myMethod(); }


  • public interface MyInterface { void myMethod(); }

  • class MyInterface { void myMethod(); }

Question 3

What will be the output of the following code?


  • 10

  • Compilation Error

  • Runtime Error

  • NullPointerException


Question 4

Can an interface method be private?

  • Yes, but only in Java 9 and later


  • No, interface methods must always be public

  • Yes, in any Java version

  • Only if the method is static

Question 5

What is the main difference between class and interface?


  • Class can’t have variables

  • Interface can be instantiated

  • Interface can’t have method bodies (pre Java 8)

  • Class has only abstract methods

Question 6

Which Java feature allows multiple inheritance of type?


  • Interface


  • Abstract class


  • Inheritance

  • Static block


Question 7

Can an interface have a method body?

  • No, never

  • No, only abstract methods

  • Yes, using default and static methods (Java 8+)

  • yes, but only private methods

Question 8

How many abstract methods can a functional interface have?


  • 0

  • 1

  • 2

  • Unlimited

Question 9

Which of the following is a valid functional interface in Java?

  • Comparator

  • Runnable


  • Callable

  • All of the above


There are 9 questions to complete.

Take a part in the ongoing discussion