Java Quiz October 6, 2024 | No Comments 0 votes, 0 avg 353 123456789101112131415 Java Questions 1 / 15 1. What will be the output of the following Java code? class A { public int i; protected int j; } class B extends A { int j; void display() { super.j = 3; System.out.println(i + " " + j); } } class Output { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } } A. 1 2 B. 2 1 C. 1 3 D. 3 1 2 / 15 2. What will be the output of the following Java code? class output { public static void main(String args[]) { String a = "hello i love java"; System.out.println(a.indexOf('i')+" "+a.indexOf('o') +" "+a.lastIndexOf('i')+" "+a.lastIndexOf('o')); } } A. 6 4 6 9 B. 5 4 5 9 C. 7 8 8 9 D. 4 3 6 9 3 / 15 3. What will be the output of the following Java program? class String_demo { public static void main(String args[]) { int ascii[] = { 65, 66, 67, 68}; String s = new String(ascii, 1, 3); System.out.println(s); } } A. ABC B. BCD C. CDA D. ABCD 4 / 15 4. What will be the output of the following Java program? class recursion { int func (int n) { int result; result = func (n - 1); return result; } } class Output { public static void main(String args[]) { recursion obj = new recursion() ; System.out.print(obj.func(12)); } } A. O B. 1 C. Compilation error D. run time error 5 / 15 5. Find the output of the following program. class output { 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. Infinity B. NaN C. all of the above D. o.o 6 / 15 6. From the following statements which is a disadvantage of an java array? A. An array can hold primitive types data B. An array has its size that is known as array length C. An array knows only its type that it contains. Array type is checked at the compile-time D. An array holds only one type of data 7 / 15 7. What is the default value of String variable? A. “” B. '’ C. null D. not defined 8 / 15 8. What will be the output of the following Java program? class recursion { int func (int n) { int result; if (n == 1) return 1; result = func (n - 1); return result; } } class Output { public static void main(String args[]) { recursion obj = new recursion() ; System.out.print(obj.func(5)); } } A. 1 B. 120 C. O D. None of the mentioned 9 / 15 9. Which of these data types is used to store command line arguments? A. Array B. Stack C. String D. Integer 10 / 15 10. 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 11 / 15 11. What is Recursion in Java? A. Recursion is a class B. Recursion is a process of defining a method that calls other methods repeatedly C. Recursion is a process of defining a method that calls itself repeatedly D. Recursion is a process of defining a method that calls other methods which in turn call again this method 12 / 15 12. Which environment variable is used to set the java path? A. MAVEN_Path B. JavaPATH C. JAVA D. JAVA_HOME 13 / 15 13. What is the value returned by function compareTo() if the invoking string is less than the string compared? A. zero B. value less than zero C. value greater than zero D. none of the mentioned 14 / 15 14. 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 15 / 15 15. Find the output of the following code. 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; System.out.print(array_variable[i] + " "); i++; } } } A. 0 2 4 6 8 B. 1 3 5 7 9 C. 0 1 2 3 4 5 6 7 8 9 D. 1 2 3 4 5 6 7 8 9 10 Your score isThe average score is 36% LinkedIn Facebook VKontakte 0% Restart quiz By Wordpress Quiz plugin Quiz