4. Operators Flashcards

1
Q

What relational operators do you know ?

A

There are six relational operators: >, >=, <, <=, ==, and !=. The last two
(== and !=) are sometimes referred to as equality operators. Relational operators always result in a boolean value (true or false).

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

What happens when comparing reference variables ?

A

When comparing reference variables, == returns true only if both references refer to the same object.

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

What instanceof Operator does ?

A

instanceof is for reference variables only. It checks whether the object is of a particular type. The instanceof operator can be used only to test objects (or null) against class types that are in the same class hierarchy. For interfaces, an object passes the instanceof test if any of its superclasses implement the interface on the right side of the instanceof operator.

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

What is the difference between ++x/–x and x++/x– ?

A

Prefix operators (for example, ++x and –x) run before the value is used in the expression.

Postfix operators (for example, x++ and x–) run after the value is used in the expression.

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

int a = 0;

int b = 0;

if( ((5<7) || (++a < 10)) | b++ < 10 ) {

System.out.println(a);

System.out.println(b);

}

A

Console output:

0

1

|| keeps ‘a’ from being incremented, but the | allows ‘b’ to be incremented.

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