Syvum Home Page

Home > Quiz Games > Java Programming > Print Preview

Java Programming : Basic Operations : Multiple Choice

Formats Info Page Worksheet / Test Paper Quiz Review
Table

Try the Quiz : Java Programming : Basic Operations : Multiple Choice

About Button apid Just what you need to know!
eview

QuestionAnswerExplanation
The type long can be used to store values in the following range:
• -231 to 231 - 1
• -264 to 264
• -232 to 232 - 1
• -263 to 263 - 1
-263 to 263 - 1The type long is a 64-bit two's complement that can be used for long integers.
Which of the following is not a hexadecimal number?
(A) 999
(B) (hex)23
(C) 0x556
(D) 0x1F2
• (A)
• (C)
• (A) & (B)
• (A), (B) & (C)
(A) & (B)Hexadecimal numbers start with "0x" in the Java programming language.
Select the invalid assignment statements from the following:
(A) float x = 238.88;
(B) double y = 0x443;
• (A) & (C)
• (B)
• (B) & (D)
• (A) & (B)
(A) & (C)238.88 is a double in Java. To assign this value to a float, 238.88f must be used. A variable of type boolean cannot be converted to an integer in Java.
If not assigned a value, a variable of type char has the following default value:
• '\u0000'
• '\uffff'
• " " (space)
• '\u0001'
'\u0000'The value of a variable of type char is 16 bits of data formatted as a Unicode character.
15 & 29 = ?
• 44
• 13
• 14
• 12
13When written in binary format, 15 is 1111, and 29 is 11101. 1111 & 11101 is 1101, which is 13 in decimal.
27 | 8 = ?
• 8
• 19
• 35
• 27
27When written in binary format, 27 is 11011, and 8 is 1000. 11011 | 1000 is 11011, which is 27.
Identify the statements that are correct:
(A) int a = 13, a>>2 = 3
(B) int b = -8, b>>1 = -4
(C) int a = 13, a>>>2 = 3
(D) int b = -8, b>>>1 = -4
• (A), (B) & (C)
• (A), (B), (C) & (D)
• (A) & (B)
• (C) & (D)
(A), (B) & (C)The shift operation "y1 >>> y2" is identical to "y1 >> y2" for all positive values of y1. It shifts the bits in y1 to the right by y2 positions.
Consider the following code: int x, y, z;
y = 1;
z = 5;
x = 0 - (++y) + z++;

After execution of this, what will be the values of x, y and z?
x = 3, y = 2, z = 6
x = 4, y = 1, z = 5
x = -7, y = 1, z = 5
x = 4, y = 2, z = 6
x = 3, y = 2, z = 6Both y and z get incremented as a result of the last statement, but y gets incremented before and z after the assisgment of the calculated value to x.
What will be the result of the expression
a % b
when a and b are of type int and their values are a = 10 and b = 6?
• 1.66
• 4
• 1
• None of these
4The modulus operator (%) may be used with floating-point as well as integer types. It returns the remainder of a division operation. Therefore, 10 % 6 will return 4.
What will be the result of the expression
a % b
when a and b are of type int and their values are a = -17 and b = -6?
• -5
• -23
• None of these
• 5
5a % b calculates the remainder when a is divided by b
What will be the value of a after execution of the following statements:
int a = 23, b = 34;
a = ((a < b) ? (b + a) : (b - a);

• 11
• 23
• 34
• 57
Error. Cannot be executed.
57
Choose the operations that can be performed on String objects:
(A) +
(B) + =
(C) -
(D) %
(E) ^

(A) & (B)
(A)
(D)/option>
(D) & (E)
None of these
(A) & (B)The "+" and "+ =" operators are overlaoded in Java. They join the two operands into one String object.
(1 | 4) + (4 & 2) = ?
(in base ten)

• 1
• 2
• 5
• 8
• 3
5In binary, 1 | 4 is 1 | 100 = 101, which is 5 in decimal. Similarly, 4 & 2 is 100 & 10 = 0, which is 0 in decimal.
Of the following functions from the class java.lang.Math, select those that produce a value of 25, when a = 25.7.
(C)
(D) & (E)
(A)
(A), (C) & (E)
(C) & (E)
(A), (C) & (E)The funtions ceil, rint and round all return the value 25 in this case. The difference lies in the type of argument returned: ceil and rint return a double, where as round will return an int or a long, depending upon the type of a (float or double, respectively).
In the code below, what data types the variable x can have?
byte b1 = 5;
byte b2 = 10;
x = b1 * b2;(A) byte
(B) int
(C) short
(D) long
(E) float
(F) double

(A), (B), (D) & (E)
(B), (D), (E) & (F)
(B), (C) & (D)
(B), (D) & (E)
(D) & (F)
(B), (D), (E) & (F)
Given the declarations
int x , m = 2000;
short y;
byte b1 = -40, b2;
long n;
Which of the following assignment statements will evaluate correctly?
(A) x = m * b1;
(B) y = m * b1;
(C) n = m * 3L;
(D) x = m * 3L;

(A), (B) & (C)
(A), (C) & (D)
(B) & (C)
(A) & (C)
(A) & (D)
(A) & (C)
Given the declarations
boolean b;
short x1 = 100, x2 = 200, x3 = 300; Which of the following statements are evaluated to true?
(A) b = x1 * 2 == x2;
(B) b = x1 + x2 != 3 * x1;
(C) b = (x3 - 2*x2<0) || ((x3 = 400)<2**x2);
(D) b = (x3 - 2*x2>0) || ((x3 = 400) 2*x2);

(A), (B) & (C)
(A) & (C)
(A), (C) & (D)
(B) & (C)
(A) & (D)
(A) & (C)
In which of the following code fragments, is the variable x evaluated to 8?
(A) int x = 32;
x = x>>2;
(B) int x = 33;
x = x>>2;
(C) int x = 35;
x = x>>2;
(D) int x = 16;
x = x>>1;

(A), (B) & (C)
(A), (C) & (D)
(B) & (C)
(A), (B), (C) & (D)
(A) & (D)
(A), (B), (C) & (D)
Consider the following code snippet:
.....
.....
try

Error. Won't compile
Division by zero
Catch block
Division by zero
Catch block

Catch block
Which of the following represent legal flow control statements?
(A) break;
(B) break();
(C) continue outer;
(D) continue(inner);
(E) return;
(F) exit();

(A), (B) & (C)
(A), (C) & (D)
(A) & (E)
(C) & (E)
(A), (C) & (E)
(A), (C) & (E)

Try the Quiz : Java Programming : Basic Operations : Multiple Choice


Contact Info © 1999-2024 Syvum Technologies Inc. Privacy Policy Disclaimer and Copyright
Previous
-
Next
-