Search Tutorials


Java Interfaces MCQ - Multiple Choice Questions And Answers | JavaInUse

Java Interfaces MCQ - Multiple Choice Questions And Answers

Q. What is an interface in Java?

A. A class that can be instantiated
B. A blueprint of a class
C. A type of loop
D. An array in Java

Q. Can a Java interface have variables?

A. Yes, with a default value
B. No, interfaces cannot have variables
C. Yes, with a final keyword
D. Yes, with a static keyword

Q. Can a Java class implement multiple interfaces?

A. No, Java classes can only implement one interface
B. Yes, Java classes can implement multiple interfaces
C. Only if the interfaces have the same method signature
D. Only if the interfaces are marked as "extendable"

Q. Which keyword is used to implement an interface in a Java class?

A. use
B. extends
C. implements
D. interface

Q. Can methods in an interface have a method body?

A. Yes, all methods in an interface must have a method body
B. No, methods in an interface cannot have a method body
C. Only static methods can have a method body in an interface
D. Only default methods can have a method body in an interface

Q. Which of the following is a correct statement about interfaces in Java?

A. Interfaces can be instantiated directly
B. Interfaces can have constructors
C. Interfaces can extend multiple classes
D. Interfaces can have abstract methods

Q. What is the purpose of default methods in Java interfaces?

A. To provide default implementation for methods
B. To force classes to override the method
C. To prevent inheritance from interfaces
D. To make methods private

Q. In Java, can an interface extend another interface?

A. Yes, an interface can extend another interface
B. No, an interface cannot extend another interface
C. Only if the interfaces have the same method signature
D. Only if the interfaces are marked as "extendable"

Q. What is the purpose of the Predicate functional interface in Java 8?

A. To produce results
B. To consume values
C. To filter elements based on a condition
D. To transform values

Q. In Java, can an interface have private methods?

A. Yes, interfaces can have private methods
B. No, interfaces cannot have private methods
C. Only if the interface is marked as "private"
D. Only if the private methods are static

Q. Which of the following is NOT a valid type of inheritance in Java?

A. Single Inheritance
B. Multiple Inheritance
C. Hierarchical Inheritance
D. Multi-level Inheritance

Q. Which keyword is used to prevent method overriding in a Java class?

A. final
B. super
C. override
D. prevent

Q. What is the output of the following Java code snippet?

interface MyInterface { 
void myMethod();
}
public class MyClass implements MyInterface {
public static void main(String[] args) {
MyInterface obj = () -> System.out.println("Hello");
obj.myMethod();
}}
A. Error: Cannot invoke lambda expression
B. Hello
C. Compilation error
D. Null





Q. What is a marker interface in Java?

A. An interface that only contains markers like @Override
B. An interface with no methods or fields
C. An interface used for marking a class for special treatment
D. An interface used for checking errors in code

Q. Which of the following Java built-in interfaces is a functional interface?

A. Serializable
B. Comparable
C. Runnable
D. Cloneable

Q. Which of the following interfaces in Java is used to represent a collection of objects?

A. List
B. Set
C. Map
D. Collection

Q. Which of the following interfaces does Java provide for manipulating key-value pairs?

A. List
B. Set
C. Map
D. Collection

Q. Which of the following interfaces is used for sorting elements in Java?

A. List
B. Set
C. Comparator
D. Sorting

Q. Which functional interface in Java 8 is used for representing a consumer of a single input argument?

A. Supplier
B. Predicate
C. Function
D. Consumer

Q. Which method in the Function interface in Java is used for applying a function to the input argument?

A. map()
B. apply()
C. transform()
D. execute()

Q. What is an interface in Java?

A. A class that can be instantiated
B. A blueprint of a class
C. A type of loop
D. An array in Java

Q. Can a Java interface have variables?

A. Yes, with a default value
B. No, interfaces cannot have variables
C. Yes, with a final keyword
D. Yes, with a static keyword

Q. Can a Java class implement multiple interfaces?

A. No, Java classes can only implement one interface
B. Yes, Java classes can implement multiple interfaces
C. Only if the interfaces have the same method signature
D. Only if the interfaces are marked as "extendable"

Q. Which keyword is used to implement an interface in a Java class?

A. use
B. extends
C. implements
D. interface

Q. Can methods in an interface have a method body?

A. Yes, all methods in an interface must have a method body
B. No, methods in an interface cannot have a method body
C. Only static methods can have a method body in an interface
D. Only default methods can have a method body in an interface

Q. Which of the following is a correct statement about interfaces in Java?

A. Interfaces can be instantiated directly
B. Interfaces can have constructors
C. Interfaces can extend multiple classes
D. Interfaces can have abstract methods

Q. What is the purpose of default methods in Java interfaces?

A. To provide default implementation for methods
B. To force classes to override the method
C. To prevent inheritance from interfaces
D. To make methods private

Q. In Java, can an interface extend another interface?

A. Yes, an interface can extend another interface
B. No, an interface cannot extend another interface
C. Only if the interfaces have the same method signature
D. Only if the interfaces are marked as "extendable"

Q. What is the purpose of the Predicate functional interface in Java 8?

A. To produce results
B. To consume values
C. To filter elements based on a condition
D. To transform values

Q. In Java, can an interface have private methods?

A. Yes, interfaces can have private methods
B. No, interfaces cannot have private methods
C. Only if the interface is marked as "private"
D. Only if the private methods are static

Q. Which of the following is NOT a valid type of inheritance in Java?

A. Single Inheritance
B. Multiple Inheritance
C. Hierarchical Inheritance
D. Multi-level Inheritance

Q. Which keyword is used to prevent method overriding in a Java class?

A. final
B. super
C. override
D. prevent

Q. What is the output of the following Java code snippet?

    
interface MyInterface {
void myMethod();
}
public class MyClass implements MyInterface {
public static void main(String[] args) {
MyInterface obj = () -> System.out.println("Hello");
obj.myMethod();
}}
A. Error: Cannot invoke lambda expression
B. Hello
C. Compilation error
D. Null

Q. What is a marker interface in Java?

A. An interface that only contains markers like @Override
B. An interface with no methods or fields
C. An interface used for marking a class for special treatment
D. An interface used for checking errors in code

Q. Which of the following Java built-in interfaces is a functional interface?

A. Serializable
B. Comparable
C. Runnable
D. Cloneable

Q. Which of the following interfaces in Java is used to represent a collection of objects?

A. List
B. Set
C. Map
D. Collection

Q. Which of the following interfaces does Java provide for manipulating key-value pairs?

A. List
B. Set
C. Map
D. Collection

Q. Which of the following interfaces is used for sorting elements in Java?

A. List
B. Set
C. Comparator
D. Sorting

Q. Which functional interface in Java 8 is used for representing a consumer of a single input argument?

A. Supplier
B. Predicate
C. Function
D. Consumer

Q. Which method in the Function interface in Java is used for applying a function to the input argument?

A. map()
B. apply()
C. transform()
D. execute()