Chapter 2: Operators and Statements Flashcards
Order of operations:
+
expression++
–expression
expression ++ (post-unary)
–expression (pre-unary)
+ (other unary)
Order of operations: \+ % / << instanceof
/ %
+
«_space;(shift)
instanceof (relational)
Order of operations: && | > = == ^ ? :
> (relational) == (equal/not equal) | ^ (logical) && (short circuit logical) ? : (ternary) = (assignment)
What happens when you add two numeric values of different data types?
The value with the smaller type will be promoted to the larger type
What happens when you add a floating point number with an integral number?
The integral number will be promoted to the type of the floating point number
What happens when you add a short and a byte together?
They are both promoted to int and the result is an int
What happens when you add two shorts together?
They are both promoted to int and the result is an int
What is the return value of ++8?
9
What is the return value of 7–?
7
T or F: += automatically casts the result of the right side to the type of the left side?
True
What is the return value of the assignment operator
The return value is the same as the value being assigned to the left side
What data types work with , <=, >=?
Numeric values
What is the difference between & and &&
&& is a short circuit operator. It will stop being evaluated once it finds one clause that determines the outcome of the rest of the statement
What are valid operands for ==?
Two numeric values
Two booleans
Two objects (including null and String)
T or F: The results of the ternary operator must have the same data types
False. Unless the result is being assigned to a variable, in which case both need to be valid assignments