Common Jobs

Common Jobs Logo

Java Quiz

1 / 40

1) 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);

    }

}

2 / 40

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

3 / 40

3) 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);

    }

}

4 / 40

4) 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);

    }

}

5 / 40

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

6 / 40

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

7 / 40

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

8 / 40

8) 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);

    }

}

9 / 40

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

int[] arr = new int[5];

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

10 / 40

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

11 / 40

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

12 / 40

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

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

13 / 40

13) 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);

    }

}

14 / 40

14) 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);

    }

}

15 / 40

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

16 / 40

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

String str = "hello";

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

17 / 40

17) 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));

    }

}

18 / 40

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

19 / 40

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

20 / 40

20) 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);

    }

}

21 / 40

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

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

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

22 / 40

22) Which collection class allows null elements?

23 / 40

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

24 / 40

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

25 / 40

25) 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]);

    }

}

26 / 40

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

27 / 40

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

28 / 40

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

29 / 40

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

30 / 40

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

System.out.println(10 / 0);

31 / 40

31) 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);

    }

}

32 / 40

32) 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");

        }

    }

}

33 / 40

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

34 / 40

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

35 / 40

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

36 / 40

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

37 / 40

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

38 / 40

38) 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);

    }

}

39 / 40

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

40 / 40

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

Your score is

The average score is 36%

0%