Repaso
EspaƱol
Java CoreCoreJV-07

What does final do?

Options

  1. Variable: assign once. Method: no override. Class: no extends (Correct option)
  2. It deletes the object at the end of the method call
  3. It makes a variable global, so every class can change it
  4. It marks the last line that the program will ever run

Answer

On a variable: it can be assigned only once. On a method: it cannot be overridden. On a class: it cannot be extended

Why

final means "cannot be changed or replaced", and it applies differently:

  • final variable: assigned once. For an object, the reference cannot point elsewhere, but the object's inside can still change (a final List can still receive add).
  • final method: subclasses cannot override it.
  • final class: nobody can extend it (String is final).

Remember

final = no reassign, no override, no extend.

Key terms

Practice this question in Repaso