Читать книгу OCP Oracle Certified Professional Java SE 17 Developer Study Guide - Jeanne Boyarsky - Страница 163

Checking for Unperformed Side Effects

Оглавление

Be wary of short-circuit behavior on the exam, as questions are known to alter a variable on the right side of the expression that may never be reached. This is referred to as an unperformed side effect. For example, what is the output of the following code?

int rabbit = 6; boolean bunny = (rabbit>= 6) || (++rabbit <= 7); System.out.println(rabbit);

Because rabbit >= 6 is true, the increment operator on the right side of the expression is never evaluated, so the output is 6.

OCP Oracle Certified Professional Java SE 17 Developer Study Guide

Подняться наверх