Common Jobs

Common Jobs Logo

Java Quiz

1 / 40

1) Which of the following is a correct way to declare and initialize an ArrayList in Java?

2 / 40

2) Which keyword is used to prevent a method from being overridden in Java?

3 / 40

3) What is the output of the following code snippet?

public class Main {

    public static void main(String[] args) {

        int x = 10;

        if (x > 5) {

            System.out.println("x is greater than 5");

        } else {

            System.out.println("x is less than or equal to 5");

        }

    }

}

4 / 40

4) What is the output of the following code snippet?

public class Main {

    public static void main(String[] args) {

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

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

    }

}

5 / 40

5) Which of the following is a correct way to declare a constant in Java?

6 / 40

6) What is the output of the following code snippet?

public class Main {

    public static void main(String[] args) {

        int arr[] = new int[5];

        System.out.println(arr.length);

    }

}

7 / 40

7) What is the output of the following code snippet?

public class Main {

    public static void main(String[] args) {

        String str = "Hello";

        str.concat(" World");

        System.out.println(str);

    }

}

8 / 40

8) What is the output of the following code snippet?

int[] arr = new int[5];

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

9 / 40

9) Which of the following statements is true about Java packages?

10 / 40

10) What is the correct way to create an instance of an abstract class in Java?

11 / 40

11) What is the output of the following code snippet?

System.out.println(10 / 0);

12 / 40

12) Which of the following statements is true about method overriding in Java?

13 / 40

13) Which of the following statements is true about method overloading in Java?

14 / 40

14) Which of the following is true about method overriding in Java?

15 / 40

15) What is the default value of a local variable in Java?

16 / 40

16) Which of the following is a valid declaration of a two-dimensional array in Java?

17 / 40

17) What is the output of the following code snippet?

String str = "hello";

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

18 / 40

18) Which of the following is true about constructors in Java?

19 / 40

19) What is the output of the following code snippet?

public class Main {

    public static void main(String[] args) {

        int x = 5;

        int y = 2;

        System.out.println(x % y);

    }

}

20 / 40

20) Which keyword is used to define a method that cannot be overridden in Java?

21 / 40

21) Which of the following is true about Java interfaces?

22 / 40

22) What is the output of the following code snippet?

public class Main {

    public static void main(String[] args) {

        String str = "hello";

        str.toUpperCase();

        System.out.println(str);

    }

}

23 / 40

23) Which of the following statements about Java packages is true?

24 / 40

24) Which of the following statements about static methods in Java is true?

25 / 40

25) What is the output of the following code snippet?

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

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

26 / 40

26) What is the output of the following code snippet?

public class Main {

    public static void main(String[] args) {

        System.out.println(5 + 2 * 3 / 2);

    }

}

27 / 40

27) What is the output of the following code snippet?

System.out.println(10 > 9 && 5 < 3);

28 / 40

28) What is the output of the following code snippet?

public class Main {

    public static void main(String[] args) {

        int x = 5;

        x += x++ + ++x;

        System.out.println(x);

    }

}

29 / 40

29) What is the output of the following code snippet?

public class Main {

    public static void main(String[] args) {

        String str = "Java";

        str.concat(" Programming");

        System.out.println(str);

    }

}

30 / 40

30) Which of the following is not a Java keyword?

31 / 40

31) Which of the following is a marker interface in Java?

32 / 40

32) What is the output of the following code snippet?

public class Main {

    public static void main(String[] args) {

        System.out.println(Math.ceil(2.1));

    }

}

33 / 40

33) Which keyword is used to define a constant in Java?

34 / 40

34) Which of the following is true about the "super" keyword in Java?

35 / 40

35) What is the output of the following Java code?

public class Main {

    public static void main(String[] args) {

        int x = 5;

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

    }

}

36 / 40

36) What is the output of the following code snippet?

public class Main {

    public static void main(String[] args) {

        int x = 5;

        int y = 2;

        System.out.println(x / y);

    }

}

37 / 40

37) Which of the following is not a valid Java identifier?

38 / 40

38) Which collection class allows null elements?

39 / 40

39) Which of the following is not a valid access modifier in Java?

40 / 40

40) Which keyword is used to create an object without a reference in Java?

Your score is

The average score is 38%

0%