Courseiva
Java Basics and SyntaxmediumMultiple ChoiceObjective-mapped

1Z0-811 Java Basics and Syntax Practice Question

A company requires a method that accepts an integer and returns true if the integer is even, otherwise false. Which implementation best follows Java conventions?

⚠ Common exam trap

Oracle often tests the distinction between returning a value versus printing it, and the requirement that a method returning a boolean must have a `boolean` return type, not `int` or `void`; the trap here is that candidates may choose Option C because it 'works' syntactically, overlooking the conventional naming and unnecessarily verbose code.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

public boolean isEven(int num) { return num % 2 == 0; }

It defines a method with the appropriate return type `boolean`, uses a clear and conventional name `isEven`, and returns the result of the expression `num % 2 == 0` directly. This follows Java naming conventions (camelCase with a verb for boolean methods) and leverages the fact that `%` yields the remainder, which is compared to zero to produce a boolean result.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • public void isEven(int num) { System.out.println(num%2==0); }

    Why it's wrong here

    Prints result but doesn't return it.

  • public int isEven(int num) { return num % 2; }

    Why it's wrong here

    Returns int, not boolean.

  • public boolean evenCheck(int num) { if(num%2==0) return true; else return false; }

    Why it's wrong here

    Redundant if-else; use direct return.

  • public boolean isEven(int num) { return num % 2 == 0; }

    Why this is correct

    Correct: boolean return, descriptive name, straightforward logic.

About these practice questions

One of 481 original 1Z0-811 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.