Page 173 - Computer science 868 Class 12
P. 173
C. Answer the following questions:
1. What is the syntax of declaring a variable?
Ans. <data type> <space><name of the variable> [= <value>];
where [= <value>] is optional.
2. What is the difference between an operator and an operand? Give an example.
Ans. The variables or values that are used in an expression are called operands and the symbols on which the operands work such as
+ (addition), - (subtraction), etc. are known as operators.
For example: d = a * b - c ;
Here *, - are operators; and a, b, and c are operands.
3. Define unary operators.
Ans. The operators that work on single operands are called unary operators. They contain one operand and one operator. For example,
+, -, ++, --.
4. What is the principle of the unary prefix increment operator?
Ans. The unary prefix increment operator works on the principle of “CHANGE BEFORE EXECUTION”.
5. What is the type of the following operators?
a. == b. && c. << d. >>> e. +=
Ans. a. == : Relational Operator
b. && : Logical Operator
c. << : Left Shift Operator
d. >>> : Unsigned Right Shift Operator
e. += : Shorthand Operator
6. Name the different sets of characters used in Java language.
Ans. The different sets of characters used in Java language are:
• Letters
• Digits
• Operators
• Delimiters
7. Which is the smallest unit that is recognised by Java compiler?
Ans. Token
8. What are literals?
Ans. Literals are the different constants used in Java that are assigned to a variable to be used for calculation or as per the logic of the
program.
9. What are character literals?
Ans. The character literals are any characters that are enclosed in single quotation marks. They may be letters, numbers, symbols, etc.
10. Write any two rules for declaring a variable.
Ans. The two rules for declaring a variable are as follows:
• A variable may contain any number of characters.
• It should not begin with a digit or a symbol apart from $ or _;
Unsolved Questions
A. Tick ( ) the correct option:
1. What will be the output?
double d = 1.5, D = 2.5;
System.out.println(d++ + ++D);
a. 5.5 b. 5.0
c. 0.5 d. None of these
171
Variables and Expressions 171

