Java Syntax and Fundamentals Quiz

  • Post category:Java Quiz
  • Reading time:1 mins read

Java Syntax and Fundamentals Quiz

Hello friend! Today’s tutorial is all about testing your Java knowledge. this quiz will challenge you on the core building blocks of Java programming.

From understanding variable declarations and data types to mastering control structures and basic methods, this quiz covers the most fundamental building blocks of Java programming.

1 / 25

Which of the following loops will execute the block of code exactly 5 times?

2 / 25

What will be the output of the following code?

public class Main {
public static void main(String[] args) {
String s = “Hello, World!”;
System.out.println(s.substring(7, 12));
}
}

3 / 25

Which method is used to compare two strings for equality in Java?

4 / 25

What will be the output of the following code snippet?

public class Main {
public static void main(String[] args) {
int a = 5;
int b = 10;
System.out.println(“Sum: ” + (a + b));
}
}

5 / 25

Which access modifier allows the most restricted access?

6 / 25

Which statement about Java constructors is true?

7 / 25

Which of the following statements is true about Java arrays?

8 / 25

Which loop structure would you use to ensure that the loop body is executed at least once?

9 / 25

What is the output of the following code?

public class Main {
public static void main(String[] args) {
int x = 5;
int y = 10;
System.out.println(x > y ? x : y);
}
}

10 / 25

Which keyword is used to create a constant variable in Java?

11 / 25

What is the output of the following code?

public class Main {
public static void main(String[] args) {
String s1 = “Hello”;
String s2 = “Hello”;
System.out.println(s1 == s2);
}
}

12 / 25

Which of the following is the correct way to declare a multi-dimensional array in Java?

13 / 25

Which exception is thrown when an array is accessed with an illegal index in Java?

14 / 25

Which of the following is the correct way to create an instance of a class named Person?

15 / 25

What will be the output of the following code?

public class Main {
public static void main(String[] args) {
String message = “Hello, World!”;
System.out.println(message.length());
}
}

16 / 25

What is the correct way to declare a package in Java?

17 / 25

Which of the following is NOT a primitive data type in Java?

18 / 25

What will be the output of the following code?

public class Main {
public static void main(String[] args) {
int x = 5;
int y = 10;
x = x + y;
y = x – y;
x = x – y;
System.out.println(“x: ” + x + “, y: ” + y);
}
}

19 / 25

What will be the output of the following code?

public class Main {
public static void main(String[] args) {
int num = 10;
if (num > 5) {
System.out.println(“Number is greater than 5”);
} else {
System.out.println(“Number is 5 or less”);
}
}
}

20 / 25

Which of the following is a correct variable declaration in Java?

21 / 25

What is the default value of a boolean variable in Java?

22 / 25

Which keyword is used to inherit a class in Java?

23 / 25

Which method signature is correct for a method named calculate that takes two integers as parameters and returns an integer?

24 / 25

What will be the output of the following code snippet?

public class Main {
public static void main(String[] args) {
int i = 0;
while (i < 3) {
System.out.print(i + ” “);
i++;
}
}
}

25 / 25

What will be the output of the following code?

public class Main {
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5};
System.out.println(arr[2]);
}
}

Your score is

The average score is 0%

0%