Lecture 12
Fall 2018
Narges Norouzi
Summary of mid-quarter survey
Summary
- More in-class coding demos
- More practice problems
- Bonus programming questions
- Going slower in the lecture
final
Final
-
Methods, classes, and variables can be defined as final.
-
Let’s look at what it means in each scenario
Final method
-
You cannot override final methods in subclasses
-
Private methods are implicitly final
-
Static methods are implicitly final
Final variable
-
The value of final variable will remain constant
-
You cannot change the value of final variables
-
You should immediately assign a value to final variables
-
Different types of final variables
-
Final parameter
-
Final local variable
-
Final instance variable
-
Final static variable
-
Key notes about final variables
-
An uninitialized final field of a class must be definitely assigned in every constructor of the class
-
An uninitialized final static variable must be definitely assigned in a static initializer of the class in which it is declared
Final classes
-
You cannot inherit from final classes
-
No class can extend final classes
-
Review (1)
-
Final data:
-
Constant
-
Local variables or instance variables
-
Primitives —> constant values
-
Objects —> constant references
-
- A compile-time constant that won’t ever change
- A value initialized at run time that you don’t want changed
Review (2)
-
Final Methods
-
No override
-
-
Final Class
- No subclass
Zybooks chapters we covered
- Section 2.9: final variables (but we covered more)
CMPS12A - Lecture 12
By Narges Norouzi
CMPS12A - Lecture 12
- 1,233