Java Reference
In-Depth Information
private int a;
private int b;
private int c;
a = 5;
b = 6;
c = a*b;
system.out.println (c);
In Java each variable declaration or assignment is a statement. Each statement needs to be
closed with “;” (semicolon). It is similar to what we do to complete a sentence in English
by putting a “.” (full stop) at end of the sentence. If you forget to put the semicolon at end
of a statement then the compiler will not know if your statement has completed. Thus it
will raise a compiler error. In the example given above we have declared variables a, b and
c and then assigned values to a and b. Later we assigned value of multiplication of a and
b into the variable c. The last statement “system.out.println (c);” is the instruction to com-
puter to display the content of variable c. Since variable c contains 30 (5X6) so you will
see 30 on your screen when you run this program.
In declarations of variables we have used the term “private”. Private indicates the scope of
variable as local. We will learn about scope in our next section.
Search WWH ::

Custom Search