Java MCQ Test: Java MCQs - Practice Questions
1. Which of these access modifiers makes a member visible to all classes everywhere?
2. In Java, which of these methods is defined in Object class?
3. Which of these is a correct method to convert a string to an integer in Java?
4. What does the 'static' keyword signify in Java?
5. Which of these access specifiers allows visibility only within the same package?
6. What does the 'extends' keyword do in Java?
7. Which method can clone an array in Java?
8. What is the output of: System.out.println(1 + 2 + "3");
9. What does the hashCode() method in Java return?
10. What is the correct syntax to create an object in Java?
11. What is the default value of a local variable in Java?
12. Which of these is used for detailed error tracing in Java?
13. Which of these operators is used to allocate memory to array variables in Java?
14. Which of these is not a Java feature?
15. Which method is used to get the length of a string in Java?
16. How do you declare a constant in Java?
17. What is the correct way to handle multiple exceptions in a single catch block?
18. What is the purpose of the 'static' keyword in Java?
19. 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"); } } }
20. What is the default layout manager for a JPanel?
21. What does the expression 'float a = 35 / 0' return in Java?
22. What will this code return: boolean a = true; boolean b = !true && (a = false); System.out.println(a);
23. How many threads can be executed at a time in a single core processor in Java?
24. Which of these is a valid way to create a thread?
25. Which of these is an incorrect array declaration in Java?
26. In Java, which of these is not a legal identifier?
27. Which company first developed Java?
28. What is the size of the 'int' data type in Java?
29. Which of these is a valid Java identifier?
30. Which of these is not a valid keyword in Java?
31. Which of these keywords is used to define a package in Java?
32. Which interface does java.util.Hashtable implement?
33. What is the output of 'System.out.println(2 + 2 + " = 4");'?
34. What is the term for the process of converting objects into a byte stream in Java?
35. In Java, what is the purpose of the transient keyword?
36. Which of these is a correct way to declare a multi-dimensional array in Java?
37. In Java, which of these is necessary to handle a checked exception?
38. What is the result of compiling and running a Java program with no main method?
39. What will this code print? int arr[] = {1, 2, 3, 4, 5}; System.out.println(arr[2]);
40. What is the starting point of a Java program?