CS-176 Practice Exams 1 & 2 Study Guide
What is the range of byte type type in Java? A: -128 to 127 B: None of the mentioned C: -2147483648 to 2147483647 D: -32768 to 32767
A: -128 to 127
What will be the output of the following Java code? 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.println("b is " + b.calculate(0, 1)); } } A: Compilation Error B: b is : 2 C: An exception is thrown D: b is : 1
A: Compilation Error
Can we create an instance of Enum outside of Enum itself? A: False B: True
A: False
Literals in Java must be appended by which of these? A: L or l B: L C: D D: l
A: L or l
Which of these operators can skip evaluating the right-hand operand? A: | B: && C: & D: !
B: &&
What will be the output of the following Java code? class evaluate { public static void main (String args[]) { int arr[] = new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int n = 6; n = arr[arr[n] / 2]; System.out.println(arr[n] / 2); } } A: 1 B: 0 C: 6 D: 3
B: 0
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: 41 B: 39 C: 38 D: 40
B: 39
What will be the output of the following Java program? class mainclass { public static void main(String args[]) { char a = 'A'; a++; System.out.println((int)a); } } A: 67 B: 66 C: 64 D: 65
B: 66
Literal can be which of these data types? A: Integer B: All of the mentioned C: Boolean D: Float
B: All of the Mentioned
Which of these is returned by "greater than", "less than", and "equal to" operators? A: None of the mentioned B: Boolean C: Integers D: Floating-Point Numbers
B: Boolean
What will be the output of the following Java code? 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: true false B: false true C: false false D: true true
B: False true
What will be the output of the following Java program? class c { public static void main (String args[]) { System.out.println("Hello" + args[0]); } } A: Hello world B: Hello C: Hello c D: Runtime Error
B: Hello
Which of these is necessary condition for automatic type conversion in Java? A: None of the mentioned B: The destination type is larger than source type C: The destination type can be larger or smaller than source type D: The destination type is smaller than source type
B: The destination type is larger than source type
What will be the output of the following Java code? class Relational_operator { public static void main(String args[]) { int var1 = 5; int var2 = 6; System.out.println(var1 > var2); } } A: true B: false C: 0 D: 1
B: false
How to get difference between two dates? A: Date diffInMilli = java.time.Duration.between(dateTime1, dateTime2).toMillis(); B: long diffInMilli = java.time.Duration.between(dateTime1, dateTime2).toMillis(); C: Time diffInMilli = java.time.Duration.between(dateTime1, dateTime2).toMillis();
B: long diffInMilli = java.time.Duration.between(dateTime1, dateTime2).toMillis(); LocalDateTime dateTime1 = LocalDateTime.of(2022, Month.JANUARY, 1, 12, 0, 0); LocalDateTime dateTime2 = LocalDateTime.of(2022, Month.JANUARY, 2, 12, 0, 0); long diffInMilli = java.time.Duration.between(dateTime1, dateTime2).toMillis(); System.out.println(diffInMilli); // prints 86400000
What will be the output of the following Java code? enum Season { WINTER, SPRING, SUMMER, AUTUMN }; System.out.println(Season.WINTER.ordinal()); A: 1 B: 2 C: 0 D: 3
C: 0
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: 3 and 4 B: All statements are correct C: 1 and 2 D: 2 and 3
C: 1 and 2
Which will be the output of the following Java code? class operators { public static void main(String args[]) { int var1 = 5; int var2 = 6; int var3; var3 = ++ var2 * var1 / var2 + var2; System.out.println(var3); } } A: 10 B: 56 C: 11 D: 12
C: 11
What will be the output of the following Java 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 7 B: 5 2 C: 7 5 D: 7 2
C: 7 5
Which right shift operator preserves the sign of the value? A: << B: >>= C: >> D: <<=
C: >>
Which of these statements are incorrect? A: Assignment operators run faster than their equivalent long forms B: Assignment operators are more efficiently implemented by Java run-time operators than their equivalent long forms C: None of the mentioned D: Assignment operators can be used only with numeric and character data types
C: None of the mentioned
What will be the error in the following Java code? byte b = 50; b = b * 50; A: b cannot contain value 50 B: No error in this code C: b cannot contain value 100, limited by its range D: * operator has converted b * 50 into int, which can not be converted to byte without casting
D: * operator has converted b * 50 into int, which can not be converted to byte without casting
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; result = 0; for (int i = 0; i < 6; ++i) { result = result + num[i]; System.out.println(result/6); } } } A: 16.46666666666 B: 16.34 C: 16.56666644 D: 16.46666666667
D: 16.46666667
On applying the Left shift operator, <<, on integer bits are lost one they are shifted past which position bit? A: 1 B: 33 C: 32 D: 31
D: 31 When the left shift operator, <<, is applied to an integer, bits are lost once they are shifted past the 31st position bit.
What will be the output of the following Java code? int arr[] = new int[5]; System.out.print(arr); A: 00000 B: 0 C: value stored in arr[0] D: Garbage value
D: Garbage value "[I@6d06d69c"
Modulus operator, %, can be applied to which of these? A: Both Integers and Floating-Point numbers B: Floating-Point numbers C: None of the mentioned D: Integers
D: Integers
Which of the following is the advantage of BigDecimal over double? A: Garbage Creation B: Syntax C: Memory Usage D: Precision
D: Precision
How to identify if a timezone is eligible for DayLight Saving? A: useDaylightTime() of Date class B: useDaylightTime() of Time class C: useDaylightTime() of DateTiem class D: useDaylightTime() of TimeZone class
D: useDaylightTime() of TimeZone class
How to format date from one form to another? A: SimpleDateFormat B: DateConverter C: DateFormat D: SimpleFormat
SimpleDateFormat
What will be the output of the following Java program, if we run as "java main_arguments 1 2 3"? class main_arguments { public static void main(String args[]) { String [][] argument = new String [2][2]; int x; x = argument[0].length; for (int y = 0; y < x; y++) { System.out.println(" " + argument[0][y]); } } } A: 103 B: 1 0 C: 123
Unsure :(