Chapter 2: Operators and Statements Flashcards

1
Q

Order of operations:
+
expression++
–expression

A

expression ++ (post-unary)
–expression (pre-unary)
+ (other unary)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
Order of operations:
\+
%
/
<<
instanceof
A

/ %
+
&laquo_space;(shift)
instanceof (relational)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
Order of operations:
&&
|
>
=
==
^
? :
A
> (relational)
== (equal/not equal)
| ^ (logical)
&& (short circuit logical)
? : (ternary)
= (assignment)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What happens when you add two numeric values of different data types?

A

The value with the smaller type will be promoted to the larger type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What happens when you add a floating point number with an integral number?

A

The integral number will be promoted to the type of the floating point number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What happens when you add a short and a byte together?

A

They are both promoted to int and the result is an int

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What happens when you add two shorts together?

A

They are both promoted to int and the result is an int

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the return value of ++8?

A

9

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the return value of 7–?

A

7

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

T or F: += automatically casts the result of the right side to the type of the left side?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the return value of the assignment operator

A

The return value is the same as the value being assigned to the left side

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What data types work with , <=, >=?

A

Numeric values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the difference between & and &&

A

&& 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are valid operands for ==?

A

Two numeric values
Two booleans
Two objects (including null and String)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

T or F: The results of the ternary operator must have the same data types

A

False. Unless the result is being assigned to a variable, in which case both need to be valid assignments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

T or F: A switch case must have one case

17
Q

What data types can be used for the switch cases?

A
anything that promotes to int
char
enum
String
numeric wrapper classes
18
Q

Is it mandatory to have a default case in a switch statement?

19
Q

T or F: A switch statement’s default case must be the last case

A

False. It can go anywhere in the switch

20
Q

Can the code from another case be executed after the default case?

A

Yes as long as the default case is not the last case and it has no break statement

21
Q

T or F: In a for loop, the update statment runs immediately after the evaluation statment

A

False. The update statement runs after the body executes

22
Q

Is it possible to declare multiple variables in a for loop?

23
Q

T or F: You can only update one variable in a for loop’s update statement

24
Q

What is required for a collection to be used in a for each loop?

A

The collection must implement Iterable

The data type of the variable must match the type stored in the colleciton

25
How can you break out of an outer loop from within an inner loop?
Use a label on the outer loop and use it when you call break
26
What does continue do?
Stops the execution of the current loop | Transfers control to the boolean statement at the top of the loop