PRO192

¡Supera tus tareas y exámenes ahora con Quizwiz!

5. What is Truncation is Java? a) Floating-point value assigned to an integer type. b) Integer value assigned to floating type. c) Floating-point value assigned to an Floating type. d) Integer value assigned to floating type.

a

7. What is the output of this program? class conversion { public static void main(String args[]) { double a = 295.04; int b = 300; byte c = (byte) a; byte d = (byte) b; System.out.println(c + " " + d); } } a) 38 43 b) 39 44 c) 295 300 d) 295.04 300

b

8. What is the output of this program? class conversion { public static void main(String args[]) { double a = 295.04; int b = 300; byte c = (byte) a; byte d = (byte) b; System.out.println(c + " " + d); } } a) 38 43 b) 39 44 c) 295 300 d) 295.04 300

b

9. What is the output of this program? class Output { public static void main(String args[]) { int x , y = 1; x = 10; if (x != 10 && x / 0 == 0) System.out.println(y); else System.out.println(++y); } } a) 1 b) 2 c) Runtime error owing to division by zero in if condition. d) Unpredictable behavior of program.

b

9. What is the output of this program? class Output { public static void main(String args[]) { int x, y = 1; x = 10; if (x != 10 && x / 0 == 0) System.out.println(y); else System.out.println(++y); } } a) 1 b) 2 c) Runtime error owing to division by zero in if condition. d) Unpredictable behavior of program.

b

What is the output of this program? class rightshift_operator { public static void main(String args[]) { int x; x = 10; x = x >> 1; System.out.println(x); } } a) 10 b) 5 c) 2 d) 20

b

10. What is the output of this program? class Output { public static void main(String args[]) { boolean a = true; boolean b = false; boolean c = a ^ b; System.out.println(!c); } } a) 0 b) 1 c) false d) true

c

2. Modulus operator, %, can be applied to which of these? a) Integers b) Floating - point numbers c) Both Integers and floating - point numbers. d) None of the mentioned

c

2. What should be expression1 evaluate to in using ternary operator as in this line? expression1 ? expression2 : expression3 a) Integer b) Floating - point numbers c) Boolean d) None of the mentioned

c

2. Which of these coding types is used for data type characters in Java? a) ASCII b) ISO-LATIN-1 c) UNICODE d) None of the mentioned

c

3. With x = 0, which of the following are legal lines of Java code for changing the value of x to 1? 1. x++; 2. x = x + 1; 3. x += 1; 4. x =+ 1; a) 1, 2 & 3 b) 1 & 4 c) 1, 2, 3 & 4 d) 3 & 2

c

4. If an expression contains double, int, float, long, then whole expression will promoted into which of these data types? a) long b) int c) double d) float

c

5. Which of these statements are incorrect? a) Equal to operator has least precedence. b) Brackets () have highest precedence. c) Division operator, /, has higher precedence than multiplication operator. d) Addition operator, +, and subtraction operator have equal precedence

c

5. Which one is a valid declaration of a boolean? a) boolean b1 = 1; b) boolean b2 = 'false'; c) boolean b3 = false; d) boolean b4 = 'true'

c

6. What is the output of this program? class evaluate { public static void main(String args[]) { int a[] = {1,2,3,4,5}; int d[] = a; int sum = 0; for (int j = 0; j < 3; ++j) sum += (a[j] * d[j + 1]) + (a[j + 1] * d[j]); System.out.println(sum); } } a) 38 b) 39 c) 40 d) 41

c

6. What is the output of this program? class operators { public static void main(String args[]) { int var1 = 5; int var2 = 6; int var3; var3 = ++ var2 * var1 / var2 + var2; System.out.print(var3); } } a) 10 b) 11 c) 12 d) 56

c

6. Which data type value is returned by all transcendental math functions? a) int b) float c) double d) long

c

8. What is the output of this program? class A { final public int calculate(int a, int b) { return 1; } } class B extends A { public int calculate(int a, int b) { return 2; } } public class output { public static void main(String args[]) { B object = new B(); System.out.print("b is " + b.calculate(0, 1)); } } a) b is : 2 b) b is : 1 c) Compilation Error. d) An exception is thrown at runtime.

c

8. What is the output of this program? class jump_statments { public static void main(String args[]) { int x = 2; int y = 0; for ( ; y < 10; ++y) { if (y % x == 0) continue; else if (y == 8) break; else System.out.print(y + " "); } } } a) 1 3 5 7 b) 2 4 6 8 c) 1 3 5 7 9 d) 1 2 3 4 5 6 7 8 9

c

8. What is the output of this program? class ternary_operator { public static void main(String args[]) { int x = 3; int y = ~ x; int z; z = x > y ? x : y; System.out.print(z); } } a) 0 b) 1 c) 3 d) -4

c

9. What is the output of this program? class increment { public static void main(String args[]) { int g = 3; System.out.print(++g * 8); } } a) 25 b) 24 c) 32 d) 33

c

9. Which of these lines of code will give better performance? 1. a | 4 + c >> b & 7; 2. (a | ((( 4 * c ) >> b ) & 7 )) a) 1 will give better performance as it has no parentheses. b) 2 will give better performance as it has parentheses. c) Both 1 & 2 will give equal performance. d) Dependent on the computer system.

c

What is the output of this program? class Output { public static void main(String args[]) { int x , y; x = 10; x++; --x; y = x++; System.out.println(x + " " + y); } } a) 11 11 b) 10 10 c) 11 10 d) 10 11

c

What is the output of this program? class average { public static void main(String args[]) { double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5}; double result; result = 0; for (int i = 0; i < 6; ++i) result = result + num[i]; System.out.print(result/6); } } a) 16.34 b) 16.566666644 c) 16.46666666666667 d) 16.46666666666666

c

What is the output of this program? class bitwise_operator { public static void main(String args[]) { int var1 = 42; int var2 = ~var1; System.out.print(var1 + " " + var2); } } a) 42 42 b) 43 43 c) 42 -43 d) 42 43

c

What is the output of this program? class increment { public static void main(String args[]) { double var1 = 1 + 5; double var2 = var1 / 4; int var3 = 1 + 5; int var4 = var3 / 4; System.out.print(var2 + " " + var4); } } a) 1 1 b) 0 1 c) 1.5 1 d) 1.5 1.0

c

What is the output of this program? class increment { public static void main(String args[]) { int g = 3; System.out.print(++g * 8); } } a) 25 b) 24 c) 32 d) 33

c

What is the output of this program? class mainclass { public static void main(String args[]) { boolean var1 = true; boolean var2 = false; if (var1) System.out.println(var1); else System.out.println(var2); } } a) 0 b) 1 c) true d) false

c

9. Which of these is incorrect string literal? a) "Hello World" b) "Hello\nWorld" c) "\"Hello World\"" d) "Hello world"

d

1. Which of these have highest precedence? a) () b) ++ c) *

a

1. Which of these is not a bitwise operator? a) & b) &= c) |= d) <= [expand title="View Answer"] Answer:d Explanation: <= is a relational operator. [/expand] 2. Which operator is used to invert all the digits in binary representation of a number? a) ~ b) <<< c) >>> d) ^

a

10. What is the output of this program? class Output { public static void main(String args[]) { int a = 1; int b = 2; int c = 3; a |= 4; b >>= 1; c <<= 1; a ^= c; System.out.println(a + " " + b + " " + c); } } a) 3 1 6 b) 2 2 3 c) 2 3 4 d) 3 3 6

a

10. What is the output of this program? class area { public static void main(String args[]) { double r, pi, a; r = 9.8; pi = 3.14; a = pi * r * r; System.out.println(a); } } a) 301.5656 b) 301 c) 301.56 d) 301.56560000

a

10. What is the output of this program? class dynamic_initialization { public static void main(String args[]) { double a, b; a = 3.0; b = 4.0; double c = Math.sqrt(a * a + b * b); System.out.println(c); } } a) 5.0 b) 25.0 c) 7.0 d) Compilation Error

a

2. What is the range of data type byte in Java? a) -128 to 127 b) -32768 to 32767 c) -2147483648 to 2147483647 d) None of the mentioned

a

2. Which of these are selection statements in Java? a) if() b) for() c) continue d) break

a

3. Which of the following loops will execute the body of loop even when condition controlling the loop is initially false? a) do-while b) while c) for d) None of the mentioned

a

3. Which of these values can a boolean variable contain? a) True & False b) 0 & 1 c) Any integer value d) true

a

4. An expression involving byte, int, and literal numbers is promoted to which of these? a) int b) long c) byte d) float

a

4. Decrement operator, -, decreases value of variable by what number? a) 1 b) 2 c) 3 d) 4

a

4. What is the order of precedence (highest to lowest) of following operators? 1. & 2. ^ 3. ?: a) 1 -> 2 -> 3 b) 2 -> 1 -> 3 c) 3 -> 2 -> 1 d) 2 -> 3 -> 1

a

6. What is the output of this program? class array_output { public static void main(String args[]) { char array_variable [] = new char[10]; for (int i = 0; i < 10; ++i) { array_variable[i] = 'i'; System.out.print(array_variable[i] + "" ); i++; } } } a) i i i i i b) 0 1 2 3 4 c) i j k l m d) None of the mentioned

a

6. What is the output of this program? class char_increment { public static void main(String args[]) { char c1 = 'D'; char c2 = 84; c2++; c1++; System.out.println(c1 + " " + c2); } } a) E U b) U E c) V E d) U F

a

7. What is the output of this program? class bitwise_operator { public static void main(String args[]) { int a = 3; int b = 6; int c = a | b; int d = a & b; System.out.println(c + " " + d); } } a) 7 2 b) 7 7 c) 7 5 d) 5 2

a

7. What is the output of this program? class mainclass { public static void main(String args[]) { char a = 'A'; a++; System.out.print((int)a); } } a) 66 b) 67 c) 65 d) 64

a

What is the output of this program? class Modulus { public static void main(String args[]) { double a = 25.64; int b = 25; a = a % 10; b = b % 10; System.out.println(a + " " + b); } } a) 5.640000000000001 5 b) 5.640000000000001 5.0 c) 5 5 d) 5 5.640000000000001

a

1. What is the output of relational operators? a) Integer b) Boolean c) Characters d) Double

b

1. What is the range of data type short in Java? a) -128 to 127 b) -32768 to 32767 c) -2147483648 to 2147483647 d) None of the mentioned

b

1. Which of these is data type long literal? a) 0x99fffL b) ABCDEFG c) 0x99fffa d) 99671246

b

1. Which of these is necessary condition for automatic type conversion in Java? a) The destination type is smaller than source type. b) The destination type is larger than source type. c) The destination type can be larger or smaller than source type. d) None of the mentioned

b

1. Which of these selection statements test only for equality? a) if b) switch c) if & switch d) None of the mentioned

b

10. What is the output of this program? class Output { public static void main(String args[]) { int x , y = 1; x = 10; if (x != 10 && x / 0 == 0) System.out.println(y); else System.out.println(++y); } } a) 1 b) 2 c) Runtime error owing to division by zero in if condition. d) Unpredictable behavior of program.

b

10. What is the output of this program? class asciicodes { public static void main(String args[]) { char var1 = 'A'; char var2 = 'a'; System.out.println((int)var1 + " " + (int)var2); } } a) 162 b) 65 97 c) 67 95 d) 66 98

b

3. What is the error in this code? byte b = 50; b = b * 50; a) b can not contain value 100, limited by its range. b) * operator has converted b * 50 into int, which can not be converted to byte without casting. c) b can not contain value 50. d) No error in this code

b

5. Which of these can not be used for a variable name in Java? a) identifier b) keyword c) identifier & keyword d) None of the mentioned

b

5. Which of these literals can be contained in a data type float variable? a) 1.7e-308 b) 3.4e-038 c) 1.7e+308 d) 3.4e-050

b

5. Which of these statement is incorrect? a) switch statement is more efficient than a set of nested ifs. b) two case constants in the same switch can have identical values. c) switch statement can only test for equality, whereas if statement can evaluate any type of boolean expression. d) it is possible to create a nested switch statements. View Answer

b

6. What is the output of this program? class selection_statements { public static void main(String args[]) { int var1 = 5; int var2 = 6; if ((var2 = 1) == var1) System.out.print(var2); else System.out.print(++var2); } } a) 1 b) 2 c) 3 d) 4

b

7. What is the output of this program? class array_output { public static void main(String args[]) { int array_variable [] = new int[10]; for (int i = 0; i < 10; ++i) { array_variable[i] = i/2; array_variable[i]++; System.out.print(array_variable[i] + " "); i++; } } } a) 0 2 4 6 8 b) 1 2 3 4 5 c) 0 1 2 3 4 5 6 7 8 9 d) 1 2 3 4 5 6 7 8 9 10

b

7. What is the output of this program? class comma_operator { public static void main(String args[]) { int sum = 0; for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1) sum += i; System.out.println(sum); } } a) 5 b) 6 c) 14 d) compilation error

b

1. What is the numerical range of a char in Java? a) -128 to 127 b) 0 to 256 c) 0 to 32767 d) 0 to 65535

d

1. Which of the following can be operands of arithmetic operators? a) Numeric b) Boolean c) Characters d) Both Numeric & Characters

d

10. What is the output of this program? class Output { public static void main(String args[]) { int a = 5; int b = 10; first: { second: { third: { if (a == b >> 1) break second; } System.out.println(a); } System.out.println(b); } } } a) 5 10 b) 10 5 c) 5 d) 10

d

10. What is the output of this program? class c { public void main( String[] args ) { System.out.println( "Hello" + args[0] ); } } a) Hello c b) Hello c) Hello world d) Runtime Error.

d

2. What is the prototype of the default constructor of this class? public class prototype { } a) prototype( ) b) prototype(void) c) public prototype(void) d) public prototype( )

d

2. Which of these can be returned by the operator & ? a) Integer b) Boolean c) Character d) Integer or Boolean

d

2. Which of these is returned by greater than, <, and equal to, ==, operator? a) Integers b) Floating - point numbers c) Boolean d) None of the mentioned [expand title="View Answer"] Answer:c Explanation: All relational operators return a boolean value i:e true and false. [/expand] 3. Which of the following operators can operate on a boolean variable? 1. && 2. == 3. ?: 4. += a) 3 & 2 b) 1 & 4 c) 1, 2 & 4 d) 1, 2 & 3 [expand title="View Answer"] Answer: d Explanation: Operator Short circuit AND, &&, equal to, == , ternary if-then-else, ?:, are boolean logical operators. += is an arithmetic operator it can operate only on numeric values. [/expand] 4. Which of these operators can skip evaluating right hand operand? a) ! b) | c) & d) && [expand title="View Answer"] Answer: d Explanation: Operator short circuit and, &&, and short circuit or, ||, skip evaluating right hand operand when output can be determined by left operand alone. [/expand] 5. Which of these statement is correct? a) true and false are numeric values 1 and 0. b) true and false are numeric values 0 and 1. c) true is any non zero value and false is 0. d) true and false are non numeric values. [expand title="View Answer"] Answer: d Explanation: true and false are keywords, they are non numeric values which do no relate to zero or non zero numbers. true and false are boolean values. [/expand] 6. What is the output of this program? class Relational_operator { public static void main(String args[]) { int var1 = 5; int var2 = 6; System.out.print(var1 > var2); } } a) 1 b) 0 c) true d) false

d

3. Literals in java must be appended by which of these? a) L b) l c) D d) L and I

d

3. What is the value stored in x in following lines of code? int x, y, z; x = 0; y = 1; x = y = z = 8; a) 0 b) 1 c) 9 d) 8

d

3. Which of the following are legal lines of Java code? 1. int w = (int)888.8; 2. byte x = (byte)100L; 3. long y = (byte)100; 4. byte z = (byte)100L; a) 1 and 2 b) 2 and 3 c) 3 and 4 d) All statements are correct.

d

4. Literal can be of which of these data types? a) integer b) float c) boolean d) all of the mentioned

d

4. Which of these jump statements can skip processing remainder of code in its body for a particular iteration? a) break b) return c) exit d) continue

d

4. Which of these occupy first 0 to 127 in Unicode character set used for characters in Java? a) ASCII b) ISO-LATIN-1 c) None of the mentioned d) ASCII and ISO-LATIN1

d

5. Which of these statements are incorrect? a) Assignment operators are more efficiently implemented by Java run-time system than their equivalent long forms. b) Assignment operators run faster than their equivalent long forms. c) Assignment operators can be used only with numeric and character data type. d) None

d

5. Which of these statements are incorrect? a) The left shift operator, <<, shifts all of the bite in a value to the left specified number of times. b) The right shift operator, >>, shifts all of the bite in a value to the right specified number of times. c) The left shift operator can be used as an alternative to multiplying by 2. d) The right shift operator automatically fills the higher order bits with 0.

d

7. What is the output of this program? class bool_operator { public static void main(String args[]) { boolean a = true; boolean b = !true; boolean c = a | b; boolean d = a & b; boolean e = d ? b : c; System.out.println(d + " " + e); } } a) false false b) true ture c) true false d) false true

d

7. What is the output of this program? class operators { public static void main(String args[]) { int x = 8; System.out.println(++x * 3 + " " + x); } } a) 24 8 b) 24 9 c) 27 8 d) 27 9

d

8. What is the output of this program? class leftshift_operator { public static void main(String args[]) { byte x = 64; int i; byte y; i = x << 2; y = (byte) (x << 2) System.out.print(i + " " + y); } } a) 0 64 b) 64 0 c) 0 256 d) 256 0

d

8. What is the output of this program? class variable_scope { public static void main(String args[]) { int x; x = 5; { int y = 6; System.out.print(x + " " + y); } System.out.println(x + " " + y); } } a) 5 6 5 6 b) 5 6 5 c) Runtime error d) Compilation error

d

9. What is the output of this program? class booloperators { public static void main(String args[]) { boolean var1 = true; boolean var2 = false; System.out.println((var2 & var2)); } } a) 0 b) 1 c) true d) false

d

9. What is the output of this program? class main_arguments { public static void main(String [] args) { String [][] argument = new String[2][2]; int x; argument[0] = args; x = argument[0].length; for (int y = 0; y < x; y++) System.out.print(" " + argument[0][y]); } } a) 1 1 b) 1 0 c) 1 0 3 d) 1 2 3

d

What is the output of this program? class Output { public static void main(String args[]) { int a = 1; int b = 2; int c; int d; c = ++b; d = a++; c++; b++; ++a; System.out.println(a + " " + b + " " + c); } } a) 3 2 4 b) 3 2 3 c) 2 3 4 d) 3 4 4

d


Conjuntos de estudio relacionados

California Real Estate Principles Unit 15 - Keeping Your Real Estate Liscence

View Set

6.1 Summarize general cryptography concepts

View Set

ATI MedSurg Endocrine Practice Test

View Set

Cyber Security 2023 completed 10/26/2023

View Set

Econ 40 [Cengage Test Question Compilation List]

View Set