Java Quiz October 6, 2024 | No Comments 0 votes, 0 avg 354 123456789101112131415 Java Questions 1 / 15 1. Find the output of the following code. class output { public static void main(String args[]) { StringBuffer s1 = new StringBuffer("Quiz"); StringBuffer s2 = s1.reverse(); System.out.println(s2); } } A. QuizziuQ B. ziuQQuiz C. Quiz D. ziuQ 2 / 15 2. 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 3 / 15 3. Which of these is correct about passing an argument by call-by-value process? A. Copy of argument is made into the formal parameter of the subroutine and changes made on parameters of subroutine have effect on original argument B. Copy of argument is made into the formal parameter of the subroutine C. Reference to original argument is passed to formal parameter of the subroutine D. Reference to original argument is passed to formal parameter of the subroutine and changes made on parameters of subroutine have effect on original argument 4 / 15 4. Which of these is returned by “greater than”, “less than” and “equal to” operators? A. Integers B. Floating – point numbers C. Boolean D. None of the mentioned 5 / 15 5. Which of these is an incorrect array declaration? A. int arr[] = new int[5] B. int [] arr = new int[5] C. int arr[] = new int[5] D. int arr[] = int [5] new 6 / 15 6. Which of the following is a superclass of every class in Java? A. ArrayList B. Abstract class C. Object class D. String 7 / 15 7. 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 8 / 15 8. What will be the output of the following Java program? class Output { public static void main(String args[]) { double x = 2.0; double y = 3.0; double z = Math.pow( x, y ); System.out.print(z); } } A. 9.O B. 8.O C. 4.O D. 2.O 9 / 15 9. 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 10 / 15 10. Which constructor creates an empty string buffer with the specified capacity as length. A. StringBuffer() B. StringBuffer(String str) C. StringBuffer(int capacity) D. none of the above 11 / 15 11. 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 12 / 15 12. Find the output of the following code. import java.util.Scanner; class ThisKeyword { private int a = 4; private int b = 1; void getSum(int a, int b) { this.a = a; this.b = b; System.out.println(this.a + this.b); } } public class Main { public static void main(String args[]) { ThisKeyword T = new ThisKeyword(); T.getSum(3, 5); } } A. 5 B. 9 C. 8 D. 4 13 / 15 13. Find the output of the following program. public class Solution{ public static void main(String[] args){ int[] x = {120, 200, 016}; for(int i = 0; i < x.length; i++){ System.out.print(x[i] + “ “); } } } A. 120 200 016 B. 120 200 14 C. 120 200 16 D. none of the above 14 / 15 14. What will be the output of the following Java code snippet? class abc { public static void main(String args[]) { if(args.length>0) System.out.println(args.length); } } A. The snippet compiles and runs but does not print anything B. The snippet compiles, runs and prints 0 C. The snippet compiles, runs and prints 1 D. The snippet does not compile 15 / 15 15. 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 Your score isThe average score is 36% LinkedIn Facebook VKontakte 0% Restart quiz By Wordpress Quiz plugin Quiz