Java MCQ Test: Java MCQs - Practice Questions
1. In Java, which of these is not a legal identifier?
2. Which method is used to get the length of a string in Java?
3. What is the term for the process of converting objects into a byte stream in Java?
4. What will this code return: boolean a = true; boolean b = !true && (a = false); System.out.println(a);
5. Which of these is a wrapper class in Java?
6. What is the purpose of the 'static' keyword in Java?
7. Which of these is used for detailed error tracing in Java?
8. What does JVM stand for?
9. What does the hashCode() method in Java return?
10. What is the starting point of a Java program?
11. What is the size of the 'int' data type in Java?
12. Which of these is not a valid lifecycle method in a Java Applet?
13. Which one is a valid declaration of a boolean?
14. Which of these is not a valid Java identifier?
15. Which of these is a valid way to take input in Java?
16. What does the operator '>>>' do in Java?
17. Which company first developed Java?
18. Which method can clone an array in Java?
19. What is the correct way to create an object in Java?
20. Which of these packages contains the Random class in Java?
21. Which of these is a valid Java identifier?
22. What is the correct syntax to create an object in Java?
23. Which of the following is a reserved keyword in Java?
24. What will this code print? int arr[] = {1, 2, 3, 4, 5}; System.out.println(arr[2]);
25. In Java, which of these methods is defined in Object class?
26. What is the output of: System.out.println(1 + 2 + "3");
27. Which of the following is a valid declaration of a char array?
28. What is the default value of a String variable in Java?
29. What is the purpose of 'final' keyword in Java?
30. What is the output of the following Java code? System.out.println(10 + 20 + "Hello" + 30 + 40);
31. In Java, which of these is necessary to handle a checked exception?
32. In Java, which of these can be used to achieve polymorphism?
33. Which of these is not a valid constructor declaration in Java?
34. What does the expression 'float a = 35 / 0' return in Java?
35. In Java, 'System.out.println()' is used for what purpose?
36. What is the output of this Java code snippet? int arr[] = new int[5]; System.out.println(arr);
37. Which of these is not a valid Java collection class?
38. How do you declare a constant in Java?
39. What is the starting index for arrays in Java?
40. What is the default value of a local variable in Java?
41. What will be the output of the following Java code? class Test { public static void main(String args[]) { try { int a = 0; System.out.println("a = " + a); } finally { System.out.println("finally block is executed"); } } }
42. Which company originally developed Java?
43. What is the return type of a method that does not return any value?
44. Which of these is a correct way to declare a multi-dimensional array in Java?
45. In Java, which of these can be used to fully abstract a class from its implementation?
46. Which of these data types is not primitive in Java?
47. What is the correct way to handle multiple exceptions in a single catch block?
48. Which class is the superclass of all classes in Java?
49. What is the use of the 'super' keyword in Java?
50. What is the default layout manager for a JPanel?