Java MCQ – Home
Java Basic MCQ
➤ Java Hello World MCQ
➤ Find Java Keywords
➤ Java Identifier Quiz
➤ Java Data Types Quiz
➤ If-Else MCQ in Java-1
➤ If-Else MCQ in Java-2
Object class MCQ
➤ Object Class Quiz
➤ equals() Method Quiz
➤ Hashcode Value Quiz
➤ toString() Method Quiz
➤ Clone() Method Quiz
Multithreading MCQ
➤ Define a Thread-1
➤ Define a Thread-2
➤ Get/set ThreadName
➤ Thread State MCQ
➤ Thread Priority MCQ
➤ Yield(), join() & sleep()
➤ Synchronization MCQ
➤ Interthread Comms
➤ Deadlock, Daemon
Exception Handling
➤ Exception Handling-1
➤ Exception Handling-2
➤ Exception Handling-3
➤ Java try-catch MCQ-1
➤ Java try-catch MCQ-2
➤ Java try-catch MCQ-3
➤ Nested try-catch MCQ
➤ throw Keyword MCQ
➤ finally Block MCQ-1
➤ finally Block MCQ-2
➤ throws Keyword MCQ
Generics MCQ
➤ Java Generics Quiz-1
➤ Java Generics Quiz-2
➤ Java Generics Quiz-3
Collection Framework
➤ Collections Quiz-1
➤ Collections Quiz-2
➤ ArrayList MCQ-1
➤ ArrayList MCQ-2
➤ LinkedList MCQ
➤ Vector Stack MCQ
➤ Java Cursors MCQ
➤ Java TreeSet MCQ
➤ TreeSet & Comparator
Java Predicate MCQ | We have discussed in detail regarding Java Predicate Functional Interface. Now let us see some questions about it.
Q1. Which of the following abstract method present in the Predicate interface?
A. test()
B. apply()
C. get()
D. accept()
View Answer
Answer:- A. test()Explanation: Predicate functional interface contains only one abstract method: test()
Q2. Which of the following is the static method present in the Predicate interface?
A. test()
B. and()
C. or()
D. isEqual()
View Answer
Answer:- DExplanation: Predicate functional interface contains only one static method: isEqual()
Q3. Which of the following default methods are present in the Predicate interface?
A. and()
B. or()
C. negate()
D. All the above
View Answer
Answer:- DExplanation: Predicate Functional interface contains the following 3 default methods: and(), or(), and not().
Q4. Which of the following is a Predicate interface declaration?
interface Predicate<T>
{
public boolean test(T t);
}
interface Predicate<T>
{
public boolean apply(T t);
}
interface Predicate<T,R>
{
public R test(T t);
}
interface Predicate<T,R>
{
public R apply(T t);
}
View Answer
Answer: AExplanation: Predicate interface can take only one Type parameter which represents only input type. We are not required to specify return type because return type is always boolean type.
interface Predicate{ public boolean test(T t); }
Q5. Which of the following is a valid Predicate to check whether the given Integer is divisible by 10 or not?
A. Predicate<Integer> p = i -> i%10 == 10;
B. Predicate<Integer, Boolean> p =i->i%10==0;
C. Predicate<Boolean, Integer> p =i->i%10==0;
D. None of the above
View Answer
Answer: AQ6. Which of the following is valid regarding Predicate functional interface?
A. Predicate Functional interface present in java.util.function package.
B. It is introduced in Java 1.8 version.
C. We can use Predicate to implement conditional checks.
D. It is possible to join 2 predicates into a single predicate also.
E. All the above
View Answer
Answer: EQ7. Which of the following is a valid Predicate to check whether the given user is admin or not?
A. Predicate<User> p=user->user.getRole().equals(“Admin”);
B. Predicate<Boolean> p=user->user.getRole().equals(“Admin”);
C. Predicate<User> p=(user,s=”admin”)->user.getRole().equals(s);
D. None of the above
View Answer
Answer: APredicate interface can take only one Type parameter which represents only input type. We are not required to specify return type because return type is always boolean type.
Q8. Consider the following Predicates.
Predicate<Integer> p1=i->i%2==0;
Predicate<Integer> p1=i->i>10;
Which of the following is invalid?
A. p1.and(p2)
B. p1.or(p2)
C. p1.negate(p2)
D. p1.negate()
View Answer
Answer: CExplanation: negate() method don’t take any argument.
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!