In Java, if a numeric literal (integer literal) is prefixed with a leading zero (0), it is treated as an octal (base-8) literal. Octal literals are represented using digits from 0 to 7.
For example:
int octalNumber = 075; // This is an octal literal System.out.println(octalNumber); // Output: 61 (decimal equivalent of octal 75)
In this example, the number 075 is an octal literal because it starts with a leading zero. The output of the program is the decimal equivalent of the octal number, which is 61. It's important to note that using leading zeros to represent octal literals is a feature of the language syntax in Java.
If you want to represent integers in decimal (base-10) format, simply omit the leading zero. For example:
int decimalNumber = 123; // This is a decimal literal System.out.println(decimalNumber); // Output: 123
First read the answer fully, then try to explain it in your own words. After that, open a few related questions and compare the concepts. This method helps you remember the topic for a longer time and improves exam preparation.