Language Basics: Operators Flashcards

1
Q

What does the ternary operator ?: operator do?

A

This operator is also known as the ternary operator because it uses three operands. If first operand is true, then do second operand. Otherwise, do third operand.

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

What does the instanceof operator do?

A

The instanceof operator compares an object to a specified type. You can use it to test if an object is an instance of a class, an instance of a subclass, or an instance of a class that implements a particular interface.

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

What is the difference between prefix (++i) and postfix(i++)?

A

++i will give the result of the new i.

i++ will give the result of the original i and store the new i for the next action.

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

What does the unary bitwise complement operator ~ do?

A

Inverts a bit pattern; it can be applied to any of the integral types, making every “0” a “1” and every “1” a “0”. For example, a byte contains 8 bits; applying this operator to a value whose bit pattern is “00000000” would change its pattern to “11111111”.

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

result -= 1;

A

Result = result - 1;

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

result *= 2;

A

result = result*2;

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