3.4-Assigning Values Flashcards

1
Q

How to master Operators?

A

-> You should understand 💥️Numeric Promotion💥️ … and when 💥️Casting💥️ is required

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

What is Casting?

A

-> It’s a unary operation where one data type is implicitly/explicitly converted as another data type.

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

When is Casting optional and when it’s mandatory?

A

🚀️ Casting is unnecessary when converting to a larger or widening data type
🚀️ But it is mandatory when converting to a smaller or narrowing data type.
[Over/Under Flow]

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

What is the syntax for Casting in Java?

A
-> By placing the type, enclosed in parentheses, to the left of the value you want to cast.
// DOES NOT COMPILE >>>
❌short s = 13 * 5;  
❌float f = 2.0 / 1;
// DOES COMPILE
✅short s = (short) (13 * 5);  
✅float f = (float)2.0 / 1;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the Compound assignment operator PITFALL case?

A

🤯️⚠️📣️ Compound assignment operator cannot be used when inline declaration.

🧠️ Compound assignment operators automatically perform internally type-casting.

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

📝️ What does the assignment operator returns?

A

It returns the value of the assignment

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