Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- the final variable cannot be reinitialized with another value
- the final method cannot be overridden
- the final class cannot be extended
- */
- // reinitiating the value of final variable
- class Main {
- public static void main(String[] args) {
- // create a final variable
- final int AGE = 32;
- // try to change the final variable
- AGE = 45;
- System.out.println("Age: " + AGE);
- }
- }
- /*
- output
- cannot assign a value to final variable AGE
- AGE = 45;
- ^
- 1 error
- */
Add Comment
Please, Sign In to add comment