Computer Science, asked by rptg1, 1 year ago

what is the difference between variable and literal in java

Answers

Answered by aryan02p3jd6e
2
A variable is like a storage container that can hold literals as values.
You can create a variable and assign it a value, and even change the value later. Here's an example:
4 is a literal. It represents the numeric value 4. You cannot change what 4 means.
However, if I define a variable like this:
int age = 4;
Then I'm assigning an address or a set of addresses in the computer memory to store the value "4".
Literals are what they literally say, like 4 is a numeric value, referring to the number 4. And age is a variable initialized with a value 4.
Similar questions