Question:

Write about literals in Java.

Show Hint

Literals provide a way to assign constant values directly to variables without the need for complex calculations or transformations.
Updated On: Sep 7, 2025
Hide Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

In Java, literals represent constant values directly written into the code. They are of several types: 1. **Integer Literals**: Represent integer values. - Example: `int x = 100;` 2. **Floating-Point Literals**: Represent decimal values. - Example: `double pi = 3.14159;` 3. **Character Literals**: Represent a single character enclosed in single quotes. - Example: `char grade = 'A';` 4. **Boolean Literals**: Represent boolean values, either `true` or `false`. - Example: `boolean isActive = true;` Literals can also be used to represent other data types, such as string literals, which are enclosed in double quotes.
Was this answer helpful?
0
0