Course Content
Introduction to Java
Variables
A variable is a piece of data that has a name and value. It stores information that can be used later in a program. Variables are declared before they are used. It tells the compiler what kind of data the variable will hold and how much memory to set aside for it.
The syntax for variable declaration is:
Main.java
If variables are of the same type, they are separated by commas ,
.
Main.java
Initializing variables
Initializing variables is a process of assigning values to them. This process of initialization can be done in two ways:
1. We call it an assignment statement by assigning a value to the variable after it has been declared.
The syntax of the assignment statement is:
Main.java
2. By assigning a value to the variable at the time of declaration - we call it an initializer.
Main.java
You can make the above two steps into one step.
Main.java
Which is the right way to define a char variable in Java? Select all correct answers.
Select the correct answer
Section 1.
Chapter 6