Saturday, July 8, 2017

JAVA INTERVIEW QUESTIONS - Operators

Operators

1) What are operators and what are the various types of operators available in Java?
Ans: Operators are special symbols used in expressions.
The following are the types of operators:
Arithmetic operators,
Assignment operators,
Increment & Decrement operators,
Logical operators,
Bitwise operators,
Comparison/Relational operators and
Conditional operators

2) The ++ operator is used for incrementing and the -- operator is used for
decrementing.
a)True
b)False
Ans: a.

3) Comparison/Logical operators are used for testing and magnitude.
a)True
b)False
Ans: a.

4) Character literals are stored as Unicode characters.
a)True
b)False
Ans: a.

5) What are the Logical operators?
Ans: OR(|), AND(&), XOR(^) AND NOT(~).

6) What is the % operator?
Ans: % operator is the modulo operator or remainder operator. It returns the remainder of dividing the first operand by the second operand.

7) What is the value of 111 % 13?
3
5
7
9
Ans: c.

8) Is &&= a valid operator?
Ans: No.

9) Can a double value be cast to a byte?
Ans: Yes

10) Can a byte object be cast to a double value?
Ans: No. An object cannot be cast to a primitive value.

11) What are the orderS of precedence and associativity?
Ans:: Order of precedence the order in which operators are evaluated in expressions.
Associativity determines whether an expression is evaluated left-right or right-left.

12) Which Java operator is right associativity?
Ans : = operator.

13) What is the difference between prefix and postfix of -- and ++ operators?
Ans : The prefix form returns the increment or decrement operation and returns the value of the increment or decrement operation.
The postfix form returns the current value of all of the expression and then
performs the increment or decrement operation on that value.

14) What is the result of expression 5.45 + "3,2"?
The double value 8.6
The string ""8.6"
The long value 8.
The String "5.453.2"
Ans : d

15) What are the values of x and y ?
x = 5; y = ++x;
Ans : x = 6; y = 6

16) What are the values of x and z?
x = 5; z = x++;
Ans : x = 6; z = 5


No comments:

Post a Comment