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

Assignment Operator

Оглавление

An assignment operator is a binary operator that modifies, or assigns, the variable on the left side of the operator with the result of the value on the right side of the equation. Unlike most other Java operators, the assignment operator is evaluated from right to left.

The simplest assignment operator is the = assignment, which you have seen already:

int herd = 1;

This statement assigns the herd variable the value of 1.

Java will automatically promote from smaller to larger data types, as you saw in the previous section on arithmetic operators, but it will throw a compiler exception if it detects that you are trying to convert from larger to smaller data types without casting. Table 2.5 lists the first assignment operator that you need to know for the exam. We present additional assignment operators later in this section.

TABLE 2.5 Simple assignment operator

Operator Example Description
Assignment int a = 50; Assigns the value on the right to the variable on the left
OCP Oracle Certified Professional Java SE 17 Developer Study Guide

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