Recent questions tagged operators

Description : If int y = 10 then find int z = (++y * (y++ + 5));

Last Answer : Ans. Increment operator has the highest precedence. So, ++y and y++ will be evaluated starting from left. In ++y, the value of y will be incremented to 11 and then 11 will be used in the expression. When y++ is evaluated, the current ... int z = (++y * (y++ + 5)); = 11 * (11 + 5 ) = 11 * 16 = 176

Description : What are the types of casting shown by the following examples: (i) char c = (char)120; (ii) int x = ‘t’;

Last Answer : Ans. (i) Explicit casting (ii) Implicit casting

Description : Name any two library packages.

Last Answer : Ans. java.util, java.io

Description : Write one difference between / and % operator.

Last Answer : Ans. / is division operator while % is modulus operator which gives the remainder on dividing two numbers.

Description : Name the operators listed below i) < ii) ++ iii) && iv) ?:

Last Answer : Ans. i) Less than comparison operator ii) Increment operator iii) And logical operator iv) Ternary operator

Description : Write the output for the following: System.out.println(“Incredible” + “\n” + “world”);

Last Answer : Incredible world

Description : System.out.print(“BEST “); System.out.println(“OF LUCK”); Choose the correct option for the output of the above statements: (i) BEST OF LUCK (ii) BEST OF LUCK

Last Answer : Ans. (i) is the correct output. System.out.print() does not add a new line at the end because of which ‘OF LUCK’ gets printed on the same line as ‘BEST’.

Description : int res = ‘A’; What is the value of res?

Last Answer : Ans. res will hold the ASCII value of ‘A’ which is 65.

Description : Classify the following as primitive or non-primitive data types: (i) char (ii) arrays (iii) int (iv) classes

Last Answer : Ans. (i) char – Primitive (ii) arrays – Non primitive (iii) int – Primitive (iv) Classes – Non primitive

Description : What is meant by a package.Give an example

Last Answer : Ans. Package in Java is a mechanism to encapsulate a group of classes, sub packages and interfaces., examples : lang , io , util etc..

Description : If the value of basic = 1500, what will be the value of tax after the following statement is executed tax = basic > 1200 ? 200 : 100

Last Answer : Ans. 200

Description : Write a difference between Unary and Binary Operator

Last Answer : Ans. Operators that acts on one operand are referred to as Unary Operators while Binary Operators acts upon two operand Unary + or Unary – , increment/decrement are the example of Unary operator While binary operator +,-,*,/ and % are the example of binary operators , (+) adds values of its operands

To see more, click for the full list of questions or popular tags.