Decisions Flashcards

1
Q

Where can labels be used?

A

On loops, switches, if statements

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

Pattern matching variable can also be?

A

Reassigned into something else inside flow scope

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

Pattern matching variable can also be?

A

Final

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

What happens if you instanceof check int primitive with Integer?

A

Casting exception

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

What happens if you instanceof check local variable with same type via pattern matching?

A

Compile error where variable is already defined

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

What happens if you instanceof check local variable with same supertype via pattern matching?

A

Compile error that pattern matching variable is supertype of local variable

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

What happens if you instanceof check local variable with same subtype via pattern matching?

A

It compiles and you have pattern matching variable

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

What is flow scoping?

A

You can define pattern matching variable while evaluating with instanceof. That variable is only available inside that check statement scope. If you negate instanceof expression, then that variable is available to all other evaluations (if-else if), but not outside evaluations scope

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

What primitives cannot be used in switch statement?

A

boolean, long, float and double

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

Can switch statement be empty?

A

Yes

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

Do switch statements support “break”?

A

Yes

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

Can cases inside switch expression be listed in same line?

A

Yes

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

Do switch expressions support “break”?

A

No

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

What are rules regarding ; in switch expressions?

A

They must appear outside expression and they must appear at the end of each case, instead of block {}. There they must appear inside code block.

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

How does switch expression look like?

A
  • It contains a type, identifier and a switch statement, but cases are comprised of arrows ->, not :. -
  • They must contain ; at the end, and at the end of each case, with exception of code blocks {}.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are rules of switch expression?

A
  • It has specific structure, different from pure switch statement
  • All possible values of switch variable must be covered by cases, or “default” case must be introduced instead
  • If expression returns multiple variable types, then “var” must be used.
  • Implicit casting of lower primitives to int is applied if return type is int
  • Direct casting of primitives is possible
  • Code block {} must yield, cannot be empty
16
Q

How is one way of creating infinite for loop?

A

for ( ; ; )

17
Q

Can for loop manage variables outside for loop from its “iteration” section?

A

Yes

17
Q

Can for loops contain more iteration variables?

A

Yes, in same line, ruled by “in same line initialization” rule

18
Q

Can variables inside for loop’s “initialization” section have same name as local variables?

A

No, “initialization” section is not isolated scope, it can use local variables