java Answer Key
java Answer Key
Q. No.
1. Which of the following is used to define a constant in Java?
a) final
b) const
c) static
d) constant
Answer: a) final
3. Which of the following data types cannot be used to create an array in Java?
a) int
b) double
c) boolean
d) void
Answer: d) void
12. Which of the following is the parent class of all classes in Java?
a) Object
b) Class
c) Throwable
d) String
Answer: a) Object
13. What is the default value of an instance variable of type String in Java?
a) ""
b) null
c) 0
d) undefined
Answer: b) null
15. Which of the following methods is used to get the length of a string in Java?
a) length()
b) size()
c) getLength()
d) count()
Answer: a) length()
20. Which of the following is the correct way to create an array of 10 integers in Java?
a) int[] arr = new int[10];
b) int arr = new int(10);
c) int arr = int[10];
d) int[10] arr = new int[];
Answer: a) int[] arr = new int[10];