0% found this document useful (0 votes)
374 views20 pages

Debugging Questions in JAVA

Uploaded by

abhiindian38
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
374 views20 pages

Debugging Questions in JAVA

Uploaded by

abhiindian38
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 20

Debugging Questions in JAVA

1. What will the following code output?

public class DebuggingExample {

public static void main(String[] args) {

int x = 10;

System.out.println(x++); // Post-increment

A) 10

B) 11

C) Compilation error

D) Runtime error

2. What does the following code snippet print?

public class DebuggingExample {

public static void main(String[] args) {

int a = 10;

int b = 20;

System.out.println(a < b ? a : b);

A) 10

B) 20

C) `a`
Debugging Questions in JAVA
D) `b`

3. What will the following code output?

public class DebuggingExample {

public static void main(String[] args) {

String str = "hello";

System.out.println(str.toUpperCase().substring(1, 4));

A) `HEL`

B) `HELLO`

C) `ELL`

D) `EL`

4. What is the output of this code?

public class DebuggingExample {

public static void main(String[] args) {

int[] arr = {1, 2, 3, 4, 5};

System.out.println(arr[5]);

A) 5

B) `ArrayIndexOutOfBoundsException`

C) `null`
Debugging Questions in JAVA
D) 4

5. What will the following code output?

public class DebuggingExample {

public static void main(String[] args) {

int i = 0;

while (i < 5) {

i++;

System.out.println(i);

A) 4

B) 5

C) 6

D) 0

6. What does the following code do?

public class DebuggingExample {

public static void main(String[] args) {

String str = "Java";

str = str.concat(" Programming");

System.out.println(str);

}
Debugging Questions in JAVA
}

A) `Java`

B) `Java Programming`

C) `JavaProgramming`

D) Compilation error

7. What will this code print?

public class DebuggingExample {

public static void main(String[] args) {

int a = 10;

int b = 0;

try {

System.out.println(a / b);

} catch (ArithmeticException e) {

System.out.println("Error");

A) `Error`

B) `Infinity`

C) `10`

D) `0`

8. What is the output of the following code?


Debugging Questions in JAVA
public class DebuggingExample {

public static void main(String[] args) {

String s = "123";

int num = Integer.parseInt(s);

System.out.println(num);

A) `123`

B) `12`

C) `null`

D) `Exception`

9. What will be the output of this code?

public class DebuggingExample {

public static void main(String[] args) {

for (int i = 0; i < 3; i++) {

System.out.println(i);

A) `0 1 2 3`

B) `0 1 2`

C) `1 2 3`
Debugging Questions in JAVA
D) `0 1`

10. What does the following code snippet do?

public class DebuggingExample {

public static void main(String[] args) {

int a = 5;

int b = a++;

System.out.println(b);

A) `5`

B) `6`

C) `4`

D) `0`

11. What will this code output?

public class DebuggingExample {

public static void main(String[] args) {

String s = "hello";

s = s.replace('l', 'r');

System.out.println(s);

A) `herro`
Debugging Questions in JAVA
B) `herro`

C) `herro`

D) `hello`

12. What does this code do?

public class DebuggingExample {

public static void main(String[] args) {

String[] arr = new String[5];

arr[0] = "one";

arr[1] = "two";

System.out.println(arr[2]);

A) `null`

B) `two`

C) `one`

D) `ArrayIndexOutOfBoundsException`

13. What will the following code output?

public class DebuggingExample {

public static void main(String[] args) {

String str = "Java";

System.out.println(str.substring(1, 4));

}
Debugging Questions in JAVA
}

A) `Java`

B) `ava`

C) `ja`

D) `a`

14. What is the output of the following code?

public class DebuggingExample {

public static void main(String[] args) {

int i = 1;

System.out.println(i++ + ++i);

A) `4`

B) `5`

C) `6`

D) `7`

15. What does the following code print?

public class DebuggingExample {

public static void main(String[] args) {

System.out.println("Hello" + 1 + 2);

}
Debugging Questions in JAVA
A) `Hello12`

B) `Hello3`

C) `Hello1 2`

D) `Hello`

16. What is the result of this code?

public class DebuggingExample {

public static void main(String[] args) {

String str = "Java";

System.out.println(str.charAt(2));

A) `J`

B) `a`

C) `v`

D) `a`

17. What will be the output of the following code?

public class DebuggingExample {

public static void main(String[] args) {

int[] nums = new int[]{1, 2, 3

};

for (int i : nums) {


Debugging Questions in JAVA
System.out.println(i);

A) `1 2 3`

B) `1`

`2`

`3`

C) `3 2 1`

D) `2 3 1`

18. What will this code output?

public class DebuggingExample {

public static void main(String[] args) {

String s = "abc";

s = s.toUpperCase();

System.out.println(s);

A) `ABC`

B) `abc`

C) `Abc`

D) `null`
Debugging Questions in JAVA
19. What will be the result of the following code?

public class DebuggingExample {

public static void main(String[] args) {

String s = "123a";

int num = Integer.parseInt(s);

System.out.println(num);

A) `123`

B) `123a`

C) `Exception`

D) `null`

20. What does this code do?

public class DebuggingExample {

public static void main(String[] args) {

int a = 5;

int b = 10;

System.out.println(++a * b--);

A) `60`

B) `55`
Debugging Questions in JAVA
C) `50`

D) `45`

21. What will be the output of this code?

public class DebuggingExample {

public static void main(String[] args) {

String str = "hello";

System.out.println(str.indexOf('l'));

A) `2`

B) `3`

C) `-1`

D) `4`

22. What is the result of this code?

public class DebuggingExample {

public static void main(String[] args) {

int[] nums = {1, 2, 3};

System.out.println(nums[nums.length]);

A) `3`

B) `IndexOutOfBoundsException`
Debugging Questions in JAVA
C) `2`

D) `null`

23. What does this code print?

public class DebuggingExample {

public static void main(String[] args) {

String str = "java";

System.out.println(str.concat(" programming").toUpperCase());

A) `java programming`

B) `JAVA PROGRAMMING`

C) `Java programming`

D) `JAVA PROGRAMMING.`

24. What is the output of this code?

public class DebuggingExample {

public static void main(String[] args) {

int a = 7;

int b = 3;

System.out.println(a % b);

A) `2`
Debugging Questions in JAVA
B) `1`

C) `0`

D) `3`

25. What will this code output?

public class DebuggingExample {

public static void main(String[] args) {

String s = "hello";

System.out.println(s.equalsIgnoreCase("HELLO"));

A) `true`

B) `false`

C) `hello`

D) `HELLO`

26. What does the following code output?

public class DebuggingExample {

public static void main(String[] args) {

System.out.println("Hello".charAt(0));

A) `H`

B) `e`
Debugging Questions in JAVA
C) `Hello`

D) `0`

27. What will be the output of this code?

public class DebuggingExample {

public static void main(String[] args) {

String str = "Java";

str = str.toLowerCase();

System.out.println(str.substring(2));

A) `java`

B) `va`

C) `ava`

D) `jav`

28. What does this code print?

public class DebuggingExample {

public static void main(String[] args) {

int[] arr = {1, 2, 3};

for (int i = 0; i < arr.length; i++) {

arr[i] = arr[i] * 2;

System.out.println(Arrays.toString(arr));
Debugging Questions in JAVA
}

A) `[2, 4, 6]`

B) `[1, 2, 3]`

C) `[2, 4, 6]`

D) `[2, 4, 6]`

29. What will the following code print?

public class DebuggingExample {

public static void main(String[] args) {

int x = 10;

System.out.println(x > 5 && x < 15);

A) `true`

B) `false`

C) `10`

D) `null`

30. What will this code output?

public class DebuggingExample {

public static void main(String[] args) {

System.out.println(2 + 3 * 4);

}
Debugging Questions in JAVA
}

A) `14`

B) `20`

C) `24`

D) `5`

31. What does the following Java code snippet do?

public class DebuggingExample {

public static void main(String[] args) {

int x = 5;

int y = 0;

try {

System.out.println(x / y);

} catch (ArithmeticException e) {

System.out.println("Cannot divide by zero.");

A) The code prints "Cannot divide by zero."

B) The code throws an ArithmeticException.

C) The code results in a compile-time error.

D) The code prints "Infinity."

32. What will be the output of the following code?


Debugging Questions in JAVA
public class DebuggingExample {

public static void main(String[] args) {

int[] numbers = {1, 2, 3, 4, 5};

for (int i = 0; i <= numbers.length; i++) {

System.out.println(numbers[i]);

A) The code will print all numbers in the array and then throw an
ArrayIndexOutOfBoundsException.

B) The code will print all numbers in the array without error.

C) The code will throw an ArrayIndexOutOfBoundsException without printing any


numbers.

D) The code will print "1 2 3 4 5" followed by an error message.

33. Given the following code, what will be the output?

public class DebuggingExample {

public static void main(String[] args) {

int a = 10;

int b = 20;

System.out.println("Before swap: a = " + a + ", b = " + b);

swap(a, b

); System.out.println("After swap: a = " + a + ", b = " + b);

}
Debugging Questions in JAVA

public static void swap(int x, int y) {

int temp = x;

x = y;

y = temp;

A) Before swap: a = 10, b = 20

After swap: a = 20, b = 10

B) Before swap: a = 10, b = 20

After swap: a = 10, b = 20

C) The code will not compile.

D) The code will throw an exception.

34. What is the result of the following code snippet?

public class DebuggingExample {

public static void main(String[] args) {

String str = null;

System.out.println(str.length());

A) The code will print 0.

B) The code will print null.


Debugging Questions in JAVA
C) The code will throw a NullPointerException.

D) The code will compile but not run.

35. Consider the following Java code. What will be the output?

public class DebuggingExample {

public static void main(String[] args) {

String str = "debugging";

System.out.println(str.substring(3, 10));

A) deb

B) ugging

C) bugging

D) debugg

You might also like