1Z0-811 Java Basics and Syntax Practice Question
A method is expected to receive an integer and return its square. Which method signature is correct?
⚠ Common exam trap
Oracle often tests the distinction between method declaration and method signature, and the trap here is that candidates may forget that a non-void method must include a 'return' statement with a matching value, or they may confuse 'void' with a return type that allows returning a value.
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
✓
int square(int x) { return x*x; }
The method signature specifies a return type of 'int' and includes the 'return' keyword to return the squared value. In Java, a method that returns a value must declare the return type before the method name and must use the 'return' statement to send the result back to the caller.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
void square(int x) { return x*x; }
Why it's wrong here
Void method cannot return a value.
- ✗
public square(int x) { return x*x; }
Why it's wrong here
Missing return type 'int'.
- ✗
int square(int x) { x*x; }
Why it's wrong here
Missing 'return' keyword.
- ✓
int square(int x) { return x*x; }
Why this is correct
Correct return type and syntax.
Go deeper
Related to this question
About these practice questions
This 1Z0-811 question is part of Courseiva's 481-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
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.