Java Practice Test – 1 Posted by Editor Date 2022-09-28 Comments 0 comment Welcome to your Java Practice Test - 1 Decide the output of the following Java code? class Test { public static void main(String[] args) { int g = -3; System.out.print(++g * 8); } } a) 16 b) -16 c) -32 d) Compile time error Decide the output of the following Java code? class Operations { 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 41 d) 42 43 Which operator is used to invert all the digits in a binary representation of a number? a) ~ b) << c) >> d) ^ What will be the output of the following Java code? class Average { public static void main(String args[]) { double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5}; double result= 0; for (int i = 0; i < num.length; ++i) result = result + num[i]; System.out.print(result/6); } } a) 16.34 b) 16.566666644 c) 16.46666666666667 d) 16.46666666666666 Decide the output of the following Java code? class Update { 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.5 1 b) 0 1 c) 1 1 d) 1.5 1.0 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 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 Decide the output of the following Java code? class NareshIt { public static void main(String args[]) { double a, b,c; a = 3.0/0; b = 0/4.0; c=0/0.0; System.out.println(a); System.out.println(b); System.out.println(c); } } a) ArithmeticException b) NumbeformatException c) Compile Time Error d) Infinity,0.0,NaN Which of these is not a bitwise operator? a) & b) &= c) |= d) <= Decide the output of the following Java code? class SampleOperations { 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 Time is Up! Time's up Share: Editor Previous post UI Technologies Practice Test - 1 2022-09-28 Next post Java Practice Test - 2 2022-09-28 You may also like Oracle Tutorial Videos 8 April, 2023 Spring Tutorial Videos 8 April, 2023 Ui Technologies Tutorial Videos 1 April, 2023