- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Interesting facts about Increment and Decrement operators in Java
There are many interesting facts with respect to increment and decrement operators in Java. We will discuss a few of them with examples −
The increment and decrement operators can’t be used with the ‘final’ variables. This is due to the fact that variables associated with ‘final’ keyword can’t be changed −
Example
public class Demo{ public static void main(String[] args){ final int my_val = 34; int my_val_2 = ++my_val; System.out.println("The value is :"); System.out.println(my_val_2); } }
Output
/Demo.java:6: error: cannot assign a value to final variable my_val int my_val_2 = ++my_val; ^ 1 error
Nesting the ‘++’ and ‘- -‘ operator isn’t possible or rather not allowed.
Example
public class Demo{ public static void main(String[] args){ int my_val_1 = 99; int my_val_2 = ++(++my_val_1); System.out.println("The value is "); System.out.println(my_val_2); } }
Output
/Demo.java:6: error: unexpected type int my_val_2 = ++(++my_val_1); ^ required: variable found: value 1 error
- Related Articles
- Increment and decrement operators in Java
- Interesting Facts about Java
- Interesting facts about null in Java
- Python Increment and Decrement Operators
- Increment and Decrement Operators in Python?
- Increment ++ and decrement -- Operators in C++
- Increment and Decrement Operators in C#
- Interesting facts about Array assignment in Java
- PHP Increment/Decrement Operators
- Interesting Facts about C Programming
- What are the restrictions on increment and decrement operators in java?
- Why avoid increment (“++”) and decrement (“--”) operators in JavaScript?
- What are increment (++) and decrement (--) operators in C#?
- Interesting facts about strings in Python
- What are some interesting facts about space?

Advertisements