final Java

Contents
Introduction
Вынос в соседний файл
.h : Заголовочные файлы
Компиляция и запуск
Пример с перегрузкой функции
Другие статьи о С++

Introduction

Ключевое слово final защищает переменные от изменений.

final переменные

Назовём файл с примером Main.java

public class Main { final int x = 10; public static void main(String[] args) { Main myObj = new Main(); myObj.x = 7; // сгенерирует ошибку System.out.println(myObj.x); } }

javac -encoding utf8 Main.java

Main.java:6: error: cannot assign a value to final variable x myObj.x = 7; ^ 1 error

Article author: Andrei Olegovich

Related articles
Development in Java
Installing Java
Install Java on Linux
Install Java on FreeBSD
Install Java on macOS
Install Java on OpenBSD
Intellij
Compiling and running Java code
final
switch
Determine the variable type
Random number generator
Import from other classes
Maven
JUnit
Banner image

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: