Core Java Online Test Questions and Answers - 2

11. Which access modifier makes a method available to all the classes in the same package and to all the subclasses of the class?

a. public
b. default
c. private
d. protected

Answer: d. protected


12. Which of the following is not a return type?

a. public
b. void
c. boolean
d. Button

Answer: a. public


13. What is a Java String's default initial value?

a. null
b. ""
c. 0
d. None of the above

Answer: a. null



14. Is an array an object in Java?

a. Yes  
b. No

Answer: a. Yes


15. Which expression can be used to access the last element of an array?

a. array[array.length]
b. array[array.length - 1]
c. array[array.length() - 1]
d array[array.length()]

Answer: b. array[array.length - 1]


16. An exception can be thrown by throws keyword explicitly.

a. Yes
b. No

Answer: b. No


17. Garbage collection cannot be forced. The programmer cannot force the JVM to free the memory used by an object.

a. Yes
b. No

Answer: a. Yes


18. All the wrapper classes (Integer, Boolean, Float, Short, Long, Double and Character) in java

a. are final
b. are private
c. are serializable
d. are immutatable

Answer: a. are final


19. Which of the following are legal identifier names in Java?

a. %abcd
b. $abcd
c. 1abcd
d. package

Answer: b. $abcd


20. Which of the following statements would compile when String s = new String("xyz"); ?

a. s = 2 * s;
b. int i = s[0];
c. s = s + s;  
d. s = s >> 2;

Answer: c. s = s + s;