Java Quiz October 6, 2024 | No Comments 0 votes, 0 avg 341 123456789101112131415 Java Questions 1 / 15 1. Identify the output of the following program. String str = “Hellow”; System.out.println(str.indexOf(‘t)); A. 1 B. null C. -1 D. o 2 / 15 2. In Iterator, hasMoreElements() method of Enumeration has been changed to: A. hasNextElement() B. isNext() C. hasNext() D. name remains same 3 / 15 3. What will be the output of the following Java code? class multidimention_array { public static void main(String args[]) { int arr[][] = new int[3][]; arr[0] = new int[1]; arr[1] = new int[2]; arr[2] = new int[3]; int sum = 0; for (int i = 0; i < 3; ++i) for (int j = 0; j < i + 1; ++j) arr[i][j] = j + 1; for (int i = 0; i < 3; ++i) for (int j = 0; j < i + 1; ++j) sum + = arr[i][j]; System.out.print(sum); } } A. 11 B. 10 C. 13 D. 14 4 / 15 4. File class is included in which package? A. java.io package B. java.util.package C. java.lang package D. java.net.package 5 / 15 5. Which of the following is not an OOPS concept in Java? A. Polymorphism B. Inheritance C. Compilation D. Encapsulation 6 / 15 6. What will be the output of the following Java code? class Output { public static void main(String args[]) { Object obj = new Object(); System.out.print(obj.getclass()); } } A. Object B. class Object C. class java.lang.Object D. Compilation Error 7 / 15 7. What will be the output of the following Java code? class Char { public static void main(String args[]) { char ch1, ch2; ch1 = 88; // code for X ch2 = 'Y'; System.out.print("ch1 and ch2: "); System.out.println(ch1 + " " + ch2); } } A. ch1 and ch2: X Y B. ch1 and ch2: x y C. ch1 and ch2: 1 3 D. None of the above 8 / 15 8. Which variables are created when an object is created with the use of the keyword 'new' and destroyed when the object is destroyed? A. Local variables B. Instance variables C. Class Variables D. Static variables 9 / 15 9. Which of these statements are incorrect? A. The left shift operator, <<, shifts all of the bits in a value to the left specified number of times B. The right shift operator, >>, shifts all of the bits 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 10 / 15 10. What will be the output of the following Java program? class Output { public static void main(String args[]) { int arr[] = {1, 2, 3, 4, 5}; for ( int i = 0; i < arr.length - 2; ++i) System.out.println(arr[i] + " "); } } A. 1 2 B. 1 2 3 C. 1 2 3 4 D. 1 2 3 4 5 11 / 15 11. Find the output of the following program. public class MyFirst { public static void main(String[] args) { MyFirst obj = new MyFirst(n); } static int a = 10; static int n; int b = 5; int c; public MyFirst(int m) { System.out.println(a + ", " + b + ", " + c + ", " + n + ", " + m); } // Instance Block { b = 30; n = 20; } // Static Block static { a = 60; } } A. 10, 5, 0, 20, 0 B. 10, 30, 20 C. 60, 5, 0, 20 D. 60, 30, 0, 20, 0 12 / 15 12. Find the output of the following program. public class Solution{ public static void main(String[] args){ short x = 10; x = x * 5; System.out.print(x); } } A. Compilation error B. 50 C. 10 D. Exception 13 / 15 13. Which statement provides an easy way to dispatch execution to different parts of your code based on the value of an expression? A. If B. Switch C. Nested-if D. If-else-if 14 / 15 14. Find the output of the following code. class overload { int x; double y; void add(int a , int b) { x = a + b; } void add(double c , double d) { y = c + d; } overload() { this.x = 0; this.y = 0; } } class Overload_methods { public static void main(String args[]) { overload obj = new overload(); int a = 2; double b = 3.2; obj.add(a, a); obj.add(b, b); System.out.println(obj.x + " " + obj.y); } } A. 4 6.4 B. 6.4 6 C. 6.4 6.4 D. 6 6 15 / 15 15. What is garbage collection in the context of Java? A. The JVM checks the output of any Java program and deletes anything that doesn’t make sense B. Any package imported in a program and not used is automatically deleted. C. When all references to an object are gone the memory used by the object is not reclaimed. D. When all references to an object are gone, the memory used by the object is automatically reclaimed. Your score isThe average score is 36% LinkedIn Facebook VKontakte 0% Restart quiz By Wordpress Quiz plugin Quiz