Final modifier Flashcards

1
Q

What entities can the Final modifier be applied to?

A

variables | methods | classes

🧠️ [Watter&Oil Rule]
🤯️⚠️📣️ Final and Abstract modifiers are NOT compatible. (Instances/Abstract Classes|method)

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

What does a final variable means?

A

final variable means CONSTANT:
primitive-variable -> CONSTANT-VALUE
referenced-variale -> CONSTANT-REFERENCE

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

What does a final method means?

A

It can NOT be OVERWRITTEN

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

What does a final class means?

A

It can NOT be EXTENDED

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

Mention some FINAL LOCAL-VARIABLE ⚠️pitfalls⚠️…

A

🧠️ COULD BE initialized
…..
A final local-variable COULD be initialized just once
✅ If NO initialized BUT NO used is ok
❌ If USED but NO initialized ⚠️WON’T COMPILE⚠️

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

Mention some FINAL INSTANCE-VARIABLE ⚠️pitfalls⚠️… (2 + BONUS)

A

🧠️ HAVE TO BE initialized (Just once)
🧠️ NON-STATIC ❌ STATIC CONTEXT
:::::…..
A final instance-variable HAVE TO be initialized
❌ If NO initialized ⚠️WON’T COMPILE⚠️
⚠️❌ non-static variable cannot be referenced from a static context
🕵‍♂️️ Could be initialized from multiple constructors (Watch out if calling this() leads to reassign value)

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

What are the INITIALIZATION-RULES for instance & static variables?
(inline | initializers | static-initializers | constructors

A

✅|✅|❌|✅* -> instance
✅|✅|❌|⚠️* -> instance final ::
✅|✅|✅|✅ -> static ::
✅|❌|✅|❌ -> static final ::

💾️🧠️🕵‍♂️️ static-context RULE
💾️🧠️🕵‍♂️️ final-instance variables HAVE TO be initialized

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

Mention some FINAL-METHOD ⚠️pitfalls⚠️… (2 + Bonus)

A

⚠️Can NOT be OVERWRITTEN
💾️🧠️🕵‍ RULE[watter&oil]
*** 🤓️🤷‍♂️️ An abstract method could be implemented as final ✅

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

Mention some FINAL-CLASSES ⚠️pitfalls⚠️… (2 + Bonus)

A
🤯️⚠️📣️ A final class cannot be extended.
💾️🧠️🕵‍ RULE[watter&oil]
      -> (Interfaces/Abstract classes)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

📝️ What does immutability means?

A

Immutability means an Object instance can’t be modified after it’s creation
🤯️⚠️📣️ Immutability concept is applicable to Object instances only.

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

Important RULES

A

💾️🧠️🕵‍♂️️ RULE[watter&oil] final and abstract modifiers are NOT compatible

💾️🧠️🕵‍♂️️ RULE[static-context] non-static variable cannot be referenced from a static context

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